[plt-scheme] Help using syntax-rules()
On Mon, 15 Mar 2010 15:24:07 -0400
David Van Horn <dvanhorn at ccs.neu.edu> wrote:
> So if you really want this syntax and you really want to write it
> using syntax-rules, then you have to parse the bindings yourself:
>
> (define-syntax toy-let ;)
> (syntax-rules ()
> [(toy-let (x ...) b ...)
> (toy-let-helper () () (x ...) b ...)]))
>
> (define-syntax toy-let-helper
> (syntax-rules ()
> [(toy-let-helper xs es (x e . r) . b)
> (toy-let-helper (x . xs) (e . es) r . b)]
> [(toy-let-helper (x ...) (e ...) () . b)
> (let ((x e) ...) . b)]))
Well, I don't know whether one would consider this cheating (since I
create nested lets instead of processing the parameters, but this would
be my attempt:
(define-syntax mylet
(syntax-rules ()
[(_ [] ?code) (let () ?code)]
[(_ [?name ?value ?rest ...] ?code)
(let ([?name ?value]) (mylet (?rest ...) ?code))]))
HTH,
Marek