[plt-scheme] Struggling with macro...
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 .....
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)]))
Rob