[racket] macro expansion function in Scheme
On Jul 12, 2011, at 9:32 AM, Bas Steunebrink wrote:
> 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?
The following experiment produces a bit more insight:
> (((eval (expand '(m y))) #t) #f)
#t
The result of expand compiles to the correct closure.
So the docs for syntax->datum are dead serious when they say that
it "returns a datum by stripping the lexical information, source
location information, properties, and tamper status from stx."
-- Matthias