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

From: Bill Clementson (bill_clementson at yahoo.com)
Date: Wed Nov 12 16:01:34 EST 2003

--- John Clements <clements at brinckerhoff.org> wrote:
> 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. 
[snip documenation for expand-to-top-form]
> 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 think the differences are starting to become clearer
to me: expand-to-top-form does a single-level
expansion while expand does a full expansion. 

However, "expand-to-top-form" is probably what many
people are interested in if they want to see what
their macro expands out into. Since "expand" expands
everything (including other macros that are referenced
inside the top-level form it provides a lot more
information. For the programmer who is just trying to
debug a macro that they've created, isn't
expand-to-top-form generally going to provide them
with the right level of expansion? To use your example
above, wouldn't (syntax-object->datum
(expand-to-top-form '(foo 12))) be the expansion that
I would do to test whether foo was doing what I
expected it to do?

So, to put it into terms that are familiar to me,
"expand-to-top-form" is similar to CL's macroexpand-1
and "expand" is similar to macroexpand?

Thanks for your patience.

Bill Clementson

Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard

Posted on the users mailing list.