[plt-scheme] Struggling with macro...

From: Jos K oot (jos.koot at telefonica.net)
Date: Wed May 23 08:32:57 EDT 2007

Hi
The ellipsis in the inner macro, it is handled by the outer macro. In order 
to push the ellipsis into the inner macro replace it by (... ...) which is a 
kind of quoting an ellipsis within a pattern or template.
Jos Koot

----- Original Message ----- 
From: "Paulo J. Matos" <pocm at soton.ac.uk>
To: <plt-scheme at list.cs.brown.edu>
Sent: Wednesday, May 23, 2007 2:03 PM
Subject: [plt-scheme] Struggling with macro...


> Hi all,
>
> Even though from time to time I can write a macro, unfortunately I
> feel they are not yet clear enough for me.
>
> I'm doing a macro to recognise the following:
> (machine <name>
>       (variables (<varname> <value>)
>                         (<varname> <value>)
>                         (<varname> <value>)
>                         etc.)
>      ... (other syntax))
>
> I've done some simple structure to keep the information of machine
> macro called mc and function to save information to structure.
> So, macro is something like this:
> (require-for-syntax "mc-utils.scm")
>
>  (define-syntax (machine stx)
>    (syntax-case stx ()
>      [(_ mname sexps ...)
>       (identifier? #'mname) ; fender
>       #'(let ([mc (make-mc () () () () ())])
>           #,(with-syntax ([variables (syntax-case #'(sexps ...) 
> (variables)
>                                        ((variables (name value) ...)
>                                         (andmap identifier? #'(name ...))
>                                         ((add-variable-to-mc #'name
> #'value) ...)))])
>               #'variables
>               #'mc))]))
>
> This gives me: syntax: no pattern variables before ellipses in template 
> in: ...
> in the second ellipsis of with-syntax.
> I want to expand:
> (machine hello
>       (variables (x 1)
>                         (y 2)
>                         (z 3)))
>
> to
> (let ([mc (make-mc () () () () ())])
>     (add-variable-to-mc x 1)
>     (add-variable-to-mc y 2)
>     (add-variable-to-mc z 3)
>     mc)
>
> It seems that no matter what I change I get some kind of wierd error.
> Can you please point me out in the right direction? (sorry for
> presenting such ugly and probably full or error macro).
>
> Cheers,
> -- 
> Paulo Jorge Matos - pocm at soton.ac.uk
> http://www.personal.soton.ac.uk/pocm
> PhD Student @ ECS
> University of Southampton, UK
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> 



Posted on the users mailing list.