[plt-scheme] Help using syntax-rules()

From: Jos Koot (jos.koot at telefonica.net)
Date: Fri Mar 26 10:12:36 EDT 2010

This is not let but let*
Jos

-----Original Message-----
From: plt-scheme-bounces at list.cs.brown.edu
[mailto:plt-scheme-bounces at list.cs.brown.edu] On Behalf Of Marek Kubica
Sent: 21 March 2010 22:30
To: David Van Horn
Cc: plt-scheme at list.cs.brown.edu
Subject: Re: [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
_________________________________________________
  For list-related administrative tasks:
  http://list.cs.brown.edu/mailman/listinfo/plt-scheme





Posted on the users mailing list.