[racket] macro expansion function in Scheme

From: Bas Steunebrink (bas at idsia.ch)
Date: Tue Jul 12 09:32:08 EDT 2011

Wow, it was right under my nose! :-) Thanks!

So I've been playing around with expand but it does not always return 
what I'd expect, particularly with making fresh variables. For example:

 > (define-syntax m
     (syntax-rules ()
       ((_ x)
        (lambda (x) (lambda (y) x)))))
 > (((m y) #t) #f)
#t   ; OK
 > (syntax->datum (expand '(m y)))
(#%expression (lambda (y) (lambda (y) y)))
 > (((lambda (y) (lambda (y) y)) #t) #f)
#f   ; So using the result of expand and syntax->datum gives something 
different

When expanding (m y), shouldn't at least one of the 2 y's be made fresh?

Best regards,
Bas



On 7/12/11 14:08 PM, Pierpaolo Bernardi wrote:
> On Tue, Jul 12, 2011 at 13:49, Bas Steunebrink <bas at idsia.ch> wrote:
>> Ciao a tutti,
>>
>> I'm looking for a Scheme function that can perform macro expansion on a
>> quoted expression. I bet someone has implemented such a thing before, 
>> but I
>> can't find it. Maybe someone can point me in the right direction?
>
> http://docs.racket-lang.org/reference/Expanding_Top-Level_Forms.html?q=expand#(def._((quote._~23~25kernel)._expand))
>
> HTH


Posted on the users mailing list.