[Prev][Next][Index][Thread]
Macro loops infinitely --- GD bug?
While hunting down a reported problem I came across the following snippet:
<code>
define macro one-definer
{ define one ?:name ?once end }
=> { define constant ?name = list(?once) }
once:
{ ?inner; ... } => { ?inner, ... }
{ ?inner } => { ?inner }
inner:
{ } => { }
{ ?:expression, ... } => { ?expression, ... }
end macro;
define one uff
1; 2, 3
end;
</code>
When compiling this in Gwydion Dylan, the compiler crashes because of stack
overflow. Probably the first pattern in #"once" gets expanded infinitely.
Before reporting this as a bug, it would be interesting to see what happens
with FD on the above code?
If I do the pattern matching myself I get this:
"1; 2, 3" matches once:1
"1" matches inner:2 and "2, 3" matches once:1
"2, 3" matches inner:2 and <empty> matches once:2 thru inner:1
At this point the recursion should stop because the whole fragment got
consumed. Where does the recursion come from then? (Yes this might be where
the bug hides in GD!)
Another issue:
Reversing the patterns in #"once" gives:
<code>
define macro one-definer
{ define one ?:name ?once end }
=> { define constant ?name = list(?once) }
once:
{ ?inner } => { ?inner }
{ ?inner; ... } => { ?inner, ... }
inner:
{ } => { }
{ ?:expression, ... } => { ?expression, ... }
end macro;
define one uff
1; 2, 3
end;
</code>
I get
Error: Syntax error in ``define one'' macro. None of the auxiliary rules
for
inner matched.
Apparently once:1 tries to match via inner:2 but "1; 2" is not an
expression.
At this point once:2 should be tried (with success) but for some reason this
does not happen. What does FD report for the second code snippet?
Thanks a lot. Either my insight is rather limited or GD is a bit buggy with
macros...
Gabor
Follow-Ups: