[plt-scheme] Macro Problem
--- Bill Wood <wtwjek at winternet.com> wrote:
> [snip explanation]
> 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 ...)))))
>
> When I load this into mzscheme (version 200) I get
>
> guarded-dos.scm:31:51: syntax: too many ellipses in template at:
> (loop var ...) in: (letrec ((loop (lambda (var ...)
> (cond (test exp ... (loop var ...)) ... (else (begin final
> ...))...
One way to work around this is to collect the (var ...) as a single
pattern variable using a helper macro. Try the following:
(define-syntax dgdo
(syntax-rules ()
((_ ((var val) ...)
(final ...)
(test exp ...) ...)
(dgdo/helper (var ...) (val ...)
(final ...) (test exp ...) ...))))
(define-syntax dgdo/helper
(syntax-rules ()
((_ all-vars (val ...)
(final ...)
(test exp ...) ...)
(letrec
((loop
(lambda all-vars
(cond (test exp ... (loop . all-vars))
...
(else (begin final ...))))))
(loop val ...)))))
Does that do what you wanted?
Ryan
__________________________________________________
Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
http://platinum.yahoo.com