[plt-scheme] Struggling with macro...
On 5/23/07, Robert Nikander <nikander at nc.rr.com> wrote:
> Paulo J. Matos wrote:
> > (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: ...
>
> The first problem is the #' before the let. Since you are using #,
> (unquote-syntax) then you need #` (or quasisyntax), not #' (or syntax).
> In other words, it must be:
>
> #`(let ([mc .....
>
Yes, thank you...
> Another problem is that in the inner syntax case #'(sexps ...) actually
> starts as:
>
> ((variables (x 1)
>
> not
>
> (variables (x 1)
>
> So, it won't match the one clause in the syntax-case. One way to help
> see this is to add lines like this to your macro, to run at transform
> time, not runtime.
>
> (printf "(sexps ...) = ~a~n" (syntax-object->datum (syntax (sexps ...))))
>
> Here is something that works, but it may not fit your real situation:
>
> (define-syntax (machine stx)
> (syntax-case stx (variables)
> [(_ mname (variables (name value) ...))
> (identifier? #'mname) ; fender
> #'(let ([mc (make-mc () () () () ())])
> (add-variable-to-mc name value) ...
> mc)]))
>
>
Indeed, although this works I don't want to do this in one go because
I have several more things besides variable declarations, so I'll
eventually need to call the macro again, kind like a cond macro, but
one which has to be wrapped around a (let ([mc... so that every code
in the expansion is able to access mc.
> Rob
>
> _________________________________________________
> 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