[racket] macros: nested templates
Hi,
I have a problem with nested templates in macros.
Consider:
(define-syntax FOO
(lambda (stx)
(syntax-case stx ()
((FOO x)
#'(let-syntax
((test (λ (stx)
(syntax-case stx ()
((test a)
#'(list a))))))
x)))))
> (FOO (test 2))
(2)
Now, I want the `test' macro to match on a variable number of arguments so as to be able to write, eg: (FOO (test 1 2 3 4))
(define-syntax FOO
(lambda (stx)
(syntax-case stx ()
((FOO x)
#'(let-syntax
((test (λ (stx)
(syntax-case stx ()
((test a ...)
#'(list a ...))))))
x)))))
This fails with:
syntax: no pattern variables before ellipses in template in: ...
I understand that the error comes from the fact that the '...' are treated as part of the first macro and therefore do not correspond to any pattern variable, but, they do correspond to a pattern variable in the generated macro (test).
Is there a clean solution to this issue?
I realize that I can write:
....
((test . a)
#'(list . a)))
....
instead of using ellipses, but then it seems to defeat the convenience of having ellipses in the first place.
Thanks,
-- Éric