> Given that many people here (including myself) don't see what
> macroexpand
> is useful for and that you find it extremely useful, would you please
> enlighten us on what you found it extremely useful for?
>
> Remember that we agreed that you cannot depend on the output that
> macroexpand produces.
I said "it doesn't matter *exactly*", as in "I don't care if (let) expands
into (lambda) or not".
Andre had an example earlier. Sam TH mentioned debugging.
Another example is pre-computing (at expansion time) as much of an
expression as possible. For example, a succession of macros might generate
something like (+ 2 (+ 3 a) b 8), and a final macro could reduce that to
(+ 5 a b 8), or even (+ 13 a b):
(define-macro (reduce exp)
(code-walker (macroexpand exp)))
Replace "+" with a memory or time-consuming operation (for example in
symbolic computation). This way you don't have to tune the individual
macros, as long as their output can be rearranged. You also allow third
parties to integrate their macros into the system easily.
Another example (or an extension of the above) is compiling (at expansion
time) a domain-specific language -- again, allowing third parties to
extend the language with their own macros. (macroexpand) gets rid of their
macros (and your own helpers), then you can compile.
I don't think you can achieve this kind of flexibility, ease and
efficiency without macroexpand.
Dan Muresan
http://alumnus.caltech.edu/~muresan
Received on Fri Sep 22 2006 - 20:42:48 UTC