Hi all,
I'm writing a macro which needs to break hygiene to introduce a function
definition. Here is my current hygienic -- and useless -- version:
(define-syntax (named-query stx)
(syntax-case stx (name-line)
[(_ (name-line (_ 0) (_ "name") magic-name))
(with-syntax ([name (string->symbol (syntax->datum #'magic-name))])
#'(define name
(lambda () (void))))]
[(_ (name-line (_ 0) (_ "name") magic-name) . rst)
(with-syntax ([name (string->symbol (syntax->datum #'magic-name))]
[modified-rst (cons (datum->syntax #'rst
always-true-line) #'rst)])
#'(define name
(lambda () (query . modified-rst))))]))
The macro invocation will look something like this:
(named-query
(name-line (offset 0) (name-type "name") "tga-image"))
I know I need to use datum->syntax to create an unhygienic function
identifier. But I'm getting hung up on the pattern variable 'magic-name'.
How the heck can I use it do this? First, I convert it from a string to a
symbol but then what? I've made various attempts but I can't figure out a
way to use it inside the template and do what I need to with it. My
attempts to use with-syntax* also fail with errors like "modified-rst:
unbound identifier in module (in phase 1, transformer environment)".
I think my general problem is that I don't understand when and how I can
use pattern variables. In this case I think I need to create a datum from
the pattern variable so I can run datum->syntax on it. But I haven't been
able to figure out how to do that in a template. For instance, this also
fails to create an identifier I can use outside of the macro:
(with-syntax ([name (datum->syntax #'magic-name (string->symbol
(syntax->datum #'magic-name)))])
I really appreciate any help.
-- Jonathan
--
You received this message because you are subscribed to the Google Groups
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/racket-users/9dfef638-35c6-4d1b-b9bb-2e6670e15140%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.