[plt-scheme] Macro tutorial question
Hello all,
I am reading through the PLT Scheme Guide section on Generating Macros (
http://docs.plt-scheme.org/guide/pattern-macros.html#(part._.Macro-.Generating_.Macros)A
number of the examples in this section depend on the macro
define-get/put-id, which is defined (seemingly just as the appropriate
macroexpansion for one case rather than for the general case) as :
(define-syntax-rule<http://docs.plt-scheme.org/reference/stx-patterns.html#(form._((lib._scheme/private/misc..ss)._define-syntax-rule))>
(define-get/put-id id get put!)
(define-syntax<http://docs.plt-scheme.org/reference/define.html#(form._((lib._scheme/private/define..ss)._define-syntax))>
clock (syntax-id-rules<http://docs.plt-scheme.org/reference/stx-patterns.html#(form._((lib._scheme/private/stxcase-scheme..ss)._syntax-id-rules))>
(set!<http://docs.plt-scheme.org/reference/set_.html#(form._((quote._~23~25kernel)._set!))>
) [(set!<http://docs.plt-scheme.org/reference/set_.html#(form._((quote._~23~25kernel)._set!))>
clock e) (put-clock! e)] [(clock a
(...<http://docs.plt-scheme.org/reference/stx-patterns.html#(form._((lib._scheme/private/stxcase-scheme..ss)._......))>
...<http://docs.plt-scheme.org/reference/stx-patterns.html#(form._((lib._scheme/private/stxcase-scheme..ss)._......))>
)) ((get-clock) a
(...<http://docs.plt-scheme.org/reference/stx-patterns.html#(form._((lib._scheme/private/stxcase-scheme..ss)._......))>
...<http://docs.plt-scheme.org/reference/stx-patterns.html#(form._((lib._scheme/private/stxcase-scheme..ss)._......))>
))] [clock (get-clock)])))
I simply adapted it to the general case and got:
(define-syntax-rule (define-get/put-id id get put!)
(define-syntax id
(syntax-id-rules (set!)
[(set! id e) (put! e)]
[(id a (... ...)) ((get) a (... ...))]
[id (get)])))
Which works, surprisingly, and confuses me. Generally define-syntax does not
evaluate the first argument but uses it as a symbol naming the item in the
syntax, but in this case, id is a identifier which gets evaluated so that
the passed value of id is used as the actual syntax. Does define-syntax
check in the environment and use the literal symbol as its name unless it
has a defined value as an identifier? I tried to look this up in the
documentation for define-syntax but quickly got confused.
Thanks,
Adam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20090722/28eb2ff5/attachment.html>