Re: Order of macroexpansion



Peter Hildebrandt <peter.hildebrandt@xxxxxxxxx> writes:

Rainer,

thanks for the quick response.

Outer is expanded. It returns a new form.
Whatever 'outer' returns will then be evaluated
as usual. Rember, the expansion of outer might
or might not have the 'inner' form.

Okay, so that means, if I create a binding in outer during expansion
time (as in my example below), this binding will be available at the
expansion of inner, right?

With the "unhygienic" status, yes.

(let (store)
(defmacro outer (val &body body) (setf store val) `(progn ,@body))
(defmacro inner (expr) `(,expr ,store)))

Beware that closure don't travel nicely thru fasl files. IIRC, it's
implementation dependent whether STORE is still shared between the
(macro-function 'outer) and (macro-function 'inner) closures after
LOAD.


So if I specify that inner is only to be used inside some surrounding
"outer", inner can be implemented this way, and I am on the safe side?

For this you should rather use macrolet:

(defmacro outer (&body body)
"
In body, you can use (INNER stuff) to do something.
"
`(let ((your-binding))
(macrolet ((inner (arg) `(progn (do-something-with your-binding) (and-your ,arg))))
,@body)))

(outer
(hi)
(inner lo)
(yo))


--
__Pascal Bourguignon__
.



Relevant Pages

  • Re: inner classes in python as inner classes in Java
    ... It's like inner method.. ... > scope with their outer method... ... different concept from that of rebinding names). ...
    (comp.lang.python)
  • Re: Order of macroexpansion
    ... Kent M Pitman wrote: ... The fact that outer is a macro means a program. ... Lisp cannot know whether inner will still even be in the expansion or, ...
    (comp.lang.lisp)
  • Re: Shed rather promise actually than believe with Evelyns lazy spoon.
    ... Many new smart draper irrigates tags without Cypriene's inner tailor. ... If the bitter pens can pull biweekly, the brave fork may hate more fires. ... Josef never believes until Ann excuses the outer frog finally. ...
    (rec.woodworking)
  • Re: Order of macroexpansion
    ... This syntax isn't a macro call. ... That is, store is first setf'd by outer, then read by inner. ... So when OUTER is being expanded the above expander function allocates ...
    (comp.lang.lisp)
  • Silk purse from sows ear stars?
    ... I made a batch of BaSO4 MgAl green stars that, ... my intention is to use at least some of these as the inner core ... So what I'm trying to decide is what outer color to apply to make the ... I'd make the outer color a shellac-fueled gypsum pink. ...
    (rec.pyrotechnics)