[plt-scheme] Where is macroexpand in PLT Scheme?

From: John Clements (clements at brinckerhoff.org)
Date: Wed Nov 12 14:27:40 EST 2003

On Wednesday, November 12, 2003, at 01:35  PM, Bill Clementson wrote:
> Nice. And very useful. However, I'm surprised that
> there isn't a :top parameter in this code. One that
> (in the case statement) would be: ((:top)
> (expand-to-top-form v))
> It seems like I'm the only person who finds the
> expand-to-top-form output more valuable than the
> expand output. This might be a consequence of me
> having come to Scheme from CL and I'm not seeing
> certain idioms that Schemers take for granted. Why do
> people prefer to see the "intermediate" (for lack of a
> better term to refer to it) output that you get from
> expand rather than the more-fully expanded output that
> you get from expand-to-top-form?

Hang on; the result of expand-to-top-form is _less_-fully expanded.  
Here's the documentation for expand-to-top-form:

"(expand-to-top-form stx-or-sexpr) partially expands syntax in 
stx-or-sexpr to reveal the outermost syntactic form. This partial 
expansion is mainly useful for detecting top-level uses of begin. 
Unlike expanding the result of expand-once, expanding the result of 
expand-to-top-form with expand produces the same result as using expand 
on the original syntax. Before stx-or-sexpr is expanded, its lexical 
context is enriched with namespace-syntax-introduce (see section 8.3)."

the key word here is 'partially'. So, for instance:

(define-syntax foo
   (syntax-rules () [(foo x) (+ x 13)]))

(syntax-object->datum (expand-to-top-form #`(+ (foo 12) 9)))


(+ (foo 12) 9)

so expand-to-top-form does nothing here.  The result of 'expand' is the 
fully-expanded output.

I agree that it's hard to read.


Posted on the users mailing list.