[plt-scheme] adding syntax transfomer to a namespace
At Fri, 14 Dec 2007 17:10:30 +0100, "Jos Koot" wrote:
> (define (add-binding name transformer)
> (eval #`(define-syntax #,name #,transformer) namespace))
>
> (add-binding 'name (syntax-rules () ((_) (list 'transformer))))
> [...]
>
> (define (add-binding name transformer)
> (eval #`(define-syntax #,name #,transformer) namespace))
>
> (add-binding #'name (syntax-rules () ((_) (list 'transformer))))
> ^^^^^^
Yes, these are different in the specific case of binding 'name, since a
symbol to `add-binding' is coerced to a syntax object using the lexical
context of the `quasisyntax' expression --- and that context includes a
local binding of `name'.
I should have suggested
(define (add-binding name transformer)
(with-syntax ([name (datum->syntax #f name)])
(eval #`(define-syntax name #,transformer))))
to avoid that particular pitfall.
Matthew