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

From: Bill Clementson (bill_clementson at yahoo.com)
Date: Wed Nov 12 13:35:53 EST 2003

--- Joe Marshall <jrm at ccs.neu.edu> wrote:
> Bill Clementson <bill_clementson at yahoo.com> writes:
> 
> >   For list-related administrative tasks:
> >  
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> >
> > I wanted to expand a macro in Scheme today. I had
> a
> > look for "macroexpand" in R5RS and the PLT
> > documenation.  Didn't find it.  At least, not in
> R5RS.
> 
> `macroexpand' would only be useful as a top-level
> debugging tool.  It
> would be quite difficult to make it work `correctly'
> with R5RS macros.
> I'm guessing that is one reason it is not in R5RS.

Very interesting comment. Could you elaborate on this
please - how is expanding an R5RS macro different from
expanding a CL macro and why is it difficult to make
it work "correctly" with R5RS macros? 

[snip]
> > Seems odd that there isn't some more convenient
> way to
> > do a macro expansion. 
> 
> I stole this from Eli Barzilay and put it in my
> mzscheme.rc file:
[snipped code]

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? 

For example, consider the following:
> (define-syntax unless
  (syntax-rules ()
    ((unless test body)
     (if (not test) body))))
> (-test (unless (eq? #t #f) (display "the world is in
harmony")))
--> (unless (eq? #t #f) (display "the world is in
harmony"))
> (-test :expand)
--> (if (#%app (#%top . not) (#%app (#%top . eq?)
(#%datum . #t) (#%datum . #f))) (#%app (#%top .
display) (#%datum . "the world is in harmony")))
> (-test (unless (eq? #t #f) (display "the world is in
harmony")))
--> (unless (eq? #t #f) (display "the world is in
harmony"))
> (-test :top)
--> (if (not (eq? #t #f)) (display "the world is in
harmony"))

To me, the output from the :top expansion is more
readable and understandable. Why do people seem to
prefer the output from :expand?

--
Bill Clementson

__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree


Posted on the users mailing list.