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

From: Joe Marshall (jrm at ccs.neu.edu)
Date: Wed Nov 12 14:29:39 EST 2003

Bill Clementson <bill_clementson at yahoo.com> writes:

> --- Joe Marshall <jrm at ccs.neu.edu> wrote:
>> `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? 

The problem is hygiene.  Free variables in the macro are supposed to
be bound to the lexical value apparent *at the macro*.

(define-syntax foo
  (syntax-rules ()
    ((foo x) (begin (display "Hello") x))))

(-test (let ((display 33)) (foo display)))
(-test :expand)
--> (let-values (((display) (#%datum . 12))) (#%app (#%top . display) (#%datum . "hi")) display)

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

The :top expansion is more readable, but it is not necessarily
correct.  The :expand expansion is correct, but less readable.

Posted on the users mailing list.