From: Erann Gat
Subject: Macroexpand and symbol-macrolet
Date: 
Message-ID: <gat-060395103046@milo.jpl.nasa.gov>
Suppose I am writing a code walker or similar piece of code and I
want to macroexpand the following form:

(symbol-macrolet ( (x '(car z)) ) (setf x 1))

to get (setf (car z) 1) or (rplaca z 1) or some such thing.

In page 204 of CLTL2 it says:

"... macroexpand-1 will also expand symbol macros defined by
symbol-macrolet ..."

so it seems like it should be possible to do this macroexpansion
without having to keep track of symbol macros myself.  But how do
I establish the symbol-macrolet environment for the expansion?  If
I just do

(macroexpand '(symbol-macrolet...

this will just expand the symbol-macrolet, which is a special form,
not a macro and therefore just expands into itself.  If I map
macroexpand over the form then macroexpand will just be called with
(setf x 5) with no context for expanding X.

How is this supposed to work?

E.

-- 

Erann Gat
···@robotics.jpl.nasa.gov
From: Barry Margolin
Subject: Re: Macroexpand and symbol-macrolet
Date: 
Message-ID: <3jjvbf$btp@tools.near.net>
In article <················@milo.jpl.nasa.gov> ···@robotics.jpl.nasa.gov (Erann Gat) writes:
>In page 204 of CLTL2 it says:
>
>"... macroexpand-1 will also expand symbol macros defined by
>symbol-macrolet ..."
>
>so it seems like it should be possible to do this macroexpansion
>without having to keep track of symbol macros myself.  

It will only be able to do this if you pass the optional environment
argument to MACROEXPAND-1.

>							But how do
>I establish the symbol-macrolet environment for the expansion?

You can only do this inside a macro or setf-expander that has received a
form that it wants to macroexpand.  The macro/setf-expander must use the
&ENVIRONMENT argument list keyword to receive the macro environment, and
then pass this to MACROEXPAND-1.

If you're writing a code walker, you'll have to emulate this yourself.

-- 
Barry Margolin
BBN Internet Services Corp.
······@near.net