[plt-scheme] adding syntax transfomer to a namespace

From: Jos Koot (jos.koot at telefonica.net)
Date: Fri Dec 14 11:10:30 EST 2007

I already tried to answer Dan Gliebold along this line, but I did not for the following caveat:

(define namespace (make-namespace))

(define (add-binding name transformer)
 (eval #`(define-syntax #,name #,transformer) namespace))

(add-binding 'name (syntax-rules () ((_) (list 'transformer))))
(eval '(name) namespace) ;--> error: reference to undefined identifier: name

The following does work:

(define namespace (make-namespace))

(define (add-binding name transformer)
 (eval #`(define-syntax #,name #,transformer) namespace))

(add-binding #'name (syntax-rules () ((_) (list 'transformer))))
             ^^^^^^
(eval '(name) namespace) ;--> (transfomer) 

Jos

((((lambda(x)((((((x x)x)x)x)x)x))
   (lambda(x)(lambda(y)(x(x y)))))
  (lambda(x)(write x)x))
 'greeting)
----- Original Message ----- 
From: "Matthew Flatt" <mflatt at cs.utah.edu>
To: "Dan Liebgold" <dan.liebgold at gmail.com>
Cc: <plt-scheme at list.cs.brown.edu>
Sent: Friday, December 14, 2007 4:41 PM
Subject: Re: [plt-scheme] adding syntax transfomer to a namespace


> At Thu, 13 Dec 2007 16:25:33 -0800, "Dan Liebgold" wrote:
>> Is there any way to emulate the behavior of define-syntax[es] by explicitly
>> defining a transformer in a namespace?   I'd like to store a transformer in
>> a list, then create a namespace later and add the transformer to it such
>> that the various expand functions will honor it.
> 
> I don't think there's any alternative to `eval' for that task:
> 
>  (define (add-binding name transformer)
>    (eval #`(define-syntax #,name #,transformer)))
> 
> All the usual caveats for using `eval' apply in this case. (Hopefully,
> those caveats will get collected in the new documentation in the near
> future).
> 
> Matthew
> 
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20071214/b70ba845/attachment.html>

Posted on the users mailing list.