From: Fernando Mato Mira
Subject: Macroexpanding
Date: 
Message-ID: <2bo7nm$f0e@disuns2.epfl.ch>
Hi,

  I want to use the macroexpansion abilities of CL to transform some
expression with the constraint that the macro symbols cannot be 
assigned a global macro function.      
  Basically, I would like to do something like this:

  (macrolet ((some-fun-name (arg) (some-fun-name arg other-arg)))
    (macroexpand '(progn ...
                         (some-fun-name actual)
                         ...)))

   and get

   '(progn ...
           (some-fun-name actual other-arg)
           ...)

   Now this does not work. I tried defining a macroexpand-hook in an
   flet in the function that takes care of this mess, so as to make
  the subexpression expansion by myself, but I think this is not working
  because macroexpand-1 does not see this 'macros', and so, does not
  call the *macroexpand-hook*.

  So, any nice portable hack? (or a non-portable one for ACL)   

  Thanks in advance

-- 
Fernando D. Mato Mira                           
Computer Graphics Lab                           
Swiss Federal Institute of Technology (EPFL)    Phone    : +41 (21) 693 - 5248
CH-1015 Lausanne                                FAX      : +41 (21) 693 - 5328
Switzerland                                     E-mail   : ········@di.epfl.ch

"Environments!!!"

From: David Richter
Subject: Re: Macroexpanding
Date: 
Message-ID: <CGB082.483@rice.edu>
In article <··········@disuns2.epfl.ch>, ········@di.epfl.ch (Fernando Mato Mira) writes:
|>   Basically, I would like to do something like this:
|> 
|>   (macrolet ((some-fun-name (arg) (some-fun-name arg other-arg)))
|>     (macroexpand '(progn ...
|>                          (some-fun-name actual)
|>                          ...)))
|> 
|>    and get
|> 
|>    '(progn ...
|>            (some-fun-name actual other-arg)
|>            ...)

I assume the local macro explicitly called in '(progn ...) (ie: it
is not in a nested call to elsewhere).  then why not use a regular
let, eg:

(let ([fn (lambda (arg) (fn arg other-arg))])
  (progn ... (fn actual) ...))
?

Or do you _really_ want to get back a quoted list from the macroexpand
call, ie: the context is something like (eval (macrolet ...)) or
(car (macrolet ...)), etc.  In that case, do something like
(do-beta 'fn '(lambda (arg) (fn arg other-arg)) '(progn ... ))
where do-beta is a substitute-and-beta-expand function (pretty simple,
really).

dr
From: Barry Margolin
Subject: Re: Macroexpanding
Date: 
Message-ID: <2c3mv1INN6qp@early-bird.think.com>
In article <··········@disuns2.epfl.ch> ········@di.epfl.ch (Fernando Mato Mira) writes:
>  I want to use the macroexpansion abilities of CL to transform some
>expression with the constraint that the macro symbols cannot be 
>assigned a global macro function.      
>  Basically, I would like to do something like this:
>
>  (macrolet ((some-fun-name (arg) (some-fun-name arg other-arg)))
>    (macroexpand '(progn ...
>                         (some-fun-name actual)
>                         ...)))

The problem is that MACROEXPAND operates at run time, but the lexical
environment (containing local macros) is only available at compile time.

If the MACROEXPAND is actually occurring inside a macro, i.e. your code
actually looks like:

(macrolet ((some-fun-name ...))
  (other-macro (progn ... (some-fun-name ...) ...)))

then OTHER-MACRO can make use of the &ENVIRONMENT lambda-list keyword in
order to receive the lexical environment.

(defmacro other-macro (form &environment env)
  (let ((expanded (macroexpand form env)))
    ...))

If you're doing explicit macroexpansion in a macro or DEFINE-SETF-METHOD,
you almost always want to do this, to make sure that the expected behavior
takes place.
-- 
Barry Margolin
System Manager, Thinking Machines Corp.

······@think.com          {uunet,harvard}!think!barmar
From: Gregor Kiczales
Subject: Re: Macroexpanding
Date: 
Message-ID: <GREGOR.93Nov13175219@calvin.parc.xerox.com>
In article <··········@disuns2.epfl.ch> ········@di.epfl.ch (Fernando Mato Mira) writes:

     I want to use the macroexpansion abilities of CL to transform some
     expression ...

     Now this does not work. I tried defining a macroexpand-hook in an ...

In PCL, there's a code walker (the file walk.lisp) that will let you
do this and other similar things having to do with properly walking
Common Lisp code and doing substitutions in it.

Gregor
From: Fernando Mato Mira
Subject: Re: Macroexpanding
Date: 
Message-ID: <2c7elc$at7@disuns2.epfl.ch>
In article <····················@calvin.parc.xerox.com>, ······@calvin.parc.xerox.com (Gregor Kiczales) writes:

> In PCL, there's a code walker (the file walk.lisp) that will let you
> do this and other similar things having to do with properly walking
> Common Lisp code and doing substitutions in it.

That's what I finally used. I fixed a couple of things for Allegro.
Who maintains this thing? I sent a copy to mkant but mail to 
CommonLoops coordinator bounced..

-- 
Fernando D. Mato Mira                           
Computer Graphics Lab                           
Swiss Federal Institute of Technology (EPFL)    Phone    : +41 (21) 693 - 5248
CH-1015 Lausanne                                FAX      : +41 (21) 693 - 5328
Switzerland                                     E-mail   : ········@di.epfl.ch

"The only good C++ is a corrupt C++."