[plt-scheme] adding syntax transfomer to a namespace

From: Dan Liebgold (dan.liebgold at gmail.com)
Date: Fri Dec 14 14:33:00 EST 2007

Why do you need to syntax rather than just quote the (define-syntax ...)
before giving it to eval?  Or would either work...?

On Dec 14, 2007 8:20 AM, Matthew Flatt <mflatt at cs.utah.edu> wrote:

> 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
>
>


-- 
Dan Liebgold    [dan.liebgold at gmail.com]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20071214/99ba5142/attachment.html>

Posted on the users mailing list.