[plt-scheme] Macro Problem
On Mar 26, Bill Wood wrote:
> ;;; (dgdo ((V1 E1) (letrec
> [...messy, especially with email wrapping...]
>
> The code I wrote is
>
> (define-syntax dgdo (syntax-rules ()
> ((dgdo ((var val) ...)
> (final ...)
> (test exp ...) ...)
> (letrec
> ((loop
> (lambda (var ...)
> (cond (test exp ... (loop var ...))
> ...
> (else (begin final ...))))))
> (loop val ...)))))
IMO, this is *much* more readable than the above...
The problem is that in the recursive call `var ...' is being repeated
for every clause and it looks like mzscheme wants to treat it as a
doubly nested macro. So it's not your understanding of syntax-rules,
but the general pattern matcher. A more compact demonstration of this
is:
(define-syntax foo
(syntax-rules ()
((x (a ...) ((b ...) ...))
(+ (* a ... b ...) ...))))
FWIW, I've checked this with scsh which fails like mzscheme but bigloo
seems to be fine with it. I don't know if this should be considered a
bug or not, but you can probably get over it easily by using
syntax-case.
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://www.barzilay.org/ Maze is Life!