[plt-scheme] adding syntax transfomer to a namespace

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Fri Dec 14 14:58:42 EST 2007

At Fri, 14 Dec 2007 11:33:00 -0800, "Dan Liebgold" wrote:
> Why do you need to syntax rather than just quote the (define-syntax ...)
> before giving it to eval?  Or would either work...?

Yes, if `define-syntax' is bound in the namespace, then just using
`quote' would work.

If you use a syntax object, then `define-syntax' doesn't have to be
bound in the namespace, because the binding is determined from its
original context.

Matthew

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


Posted on the users mailing list.