|
ALU Wiki - 25-Apr-2004 Code Walker Slides
|
|
Code walker slides and commentaryDirk's slides. Dirk's notes and errata are below. To read his PDF slides more easily, you might want to activate the "bookmarks," for which Adobe Acrobat has as a tab on the left. Slide 3For the first indicator: a good example of this is on the next slide (4), where a macro expansion needs to "spill out" of its macro call. For the second indicator: a good example is macroexpand-all (slide 7). Just because (list (foo bar)) and (quote (foo bar)) have the same form, doesn't mean they should be handled the same way. Slide 5 This slide shows that the indicators are just that: indicators. They are not infallible laws. Slide 7 BUG! Between the (macrop ...) and (t ...) clauses, a new clause should be inserted:
((consp form) (cons (car form)
(mapcar #'(lambda (arg)
(macroexpand-all arg env))
(cdr form))))
We then have four cond-clauses.
The first handles the case where the form has an associated walker-hook, the second handles the case where the form is a macrocall. We do place these in this order, and not the other way around, so that it is possible to define walker-hooks on macros as well.
The new third clause above handles the case of a normal function call. (Note that this will also handle any special operators for which we have not (yet) created a walker-hook.)
The fourth and last form handles atoms. (Note that it could just as well have been (t form), because when macrop is nil we know that form and expansion are EQ.)
Also note that there is no way to ask whether something has a macroexpansion. We just try to macroexpand and find out after the fact whether any actual macroexpansion occured. (In the Python community, this is known as EAFP (Easier to Ask Forgiveness than Permission).)
Slide 10Defining your own environment structures is not as bad as it sounds, and is used by Arnesi's CPS transform, for example. Allegro CL 6.3 will have CLTL2-constructs, if I understand it correctly. CMUCL and others define some code walking functions, macroexpand-all usually among them. I don't have any experience with this at the moment. |