[plt-scheme] Struggling with macro...

From: Paulo J. Matos (pocm at soton.ac.uk)
Date: Wed May 23 11:46:50 EDT 2007

On 5/23/07, Robert Nikander <nikander at nc.rr.com> wrote:
> Robert Nikander wrote:
> >       (let* ([sections (syntax->list #'(sexps ...))]
> >              [adds (map (λ (section)
> >                           (syntax-case section (variables thingies)
> >                             ((variables (name value) ...)
> >                              #'(begin (add-variable-to-mc mc 'name
> > value) ...))
> >                             ((thingies expr ...)
> >                              #'(begin (add-thingy-to-mc mc expr) ...))))
> >                         sections)])
>
>
> I should have used syntax-rules, for simplicity...
>
>
>               [adds (map (syntax-rules (variables thingies)
>                            ((variables (name value) ...)
>                             (begin (add-variable-to-mc mc 'name value) ...))
>                            ((thingies expr ...)
>                             (begin (add-thingy-to-mc mc expr) ...)))
>                          sections)])
>

I'm quite amazed that it worked. Mainly for 1 reason, one is that mc
is not defined when syntax-case environment, however, it seems that it
only needs to be defined in the expansion environment (or whatever it
is called).  Now, the fact that it works with syntax-rules is nice.
Even though I still get confused about when I should use syntax-rules
or syntax-case. Well, still have much to do.

Thank you very much!

>
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>
>


-- 
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK

Posted on the users mailing list.