The special operators, if you must know, are TAGBODY
and GO
. There's no need to discuss them now, but I'll cover them in Chapter 20.
89
DOLIST
is similar to Perl's foreach
or Python's for
. Java added a similar kind of loop construct with the 'enhanced' for
loop in Java 1.5, as part of JSR-201. Notice what a difference macros make. A Lisp programmer who notices a common pattern in their code can write a macro to give themselves a source-level abstraction of that pattern. A Java programmer who notices the same pattern has to convince Sun that this particular abstraction is worth adding to the language. Then Sun has to publish a JSR and convene an industry-wide 'expert group' to hash everything out. That process—according to Sun—takes an average of 18 months. After that, the compiler writers all have to go upgrade their compilers to support the new feature. And even once the Java programmer's favorite compiler supports the new version of Java, they probably
90
A variant of DO
, DO*
, assigns each variable its value before evaluating the step form for subsequent variables. For more details, consult your favorite Common Lisp reference.
91
The DOTIMES
is also preferred because the macro expansion will likely include declarations that allow the compiler to generate more efficient code.
92
LOOP
doesn't care what package the symbols are from. When the LOOP
macro parses its body, it considers any appropriately named symbols equivalent. You could even use true keywords if you wanted—:for
, :across
, and so on—because they also have the correct name. But most folks just use plain symbols. Because the loop keywords are used only as syntactic markers, it doesn't matter if they're used for other purposes—as function or variable names.
93
As with functions, macros can also contain declarations, but you don't need to worry about those for now.
94
APPEND
, which I haven't discussed yet, is a function that takes any number of list arguments and returns the result of splicing them together into a single list.
95
Another function, MACROEXPAND
, keeps expanding the result as long as the first element of the resulting expansion is the name of the macro. However, this will often show you a much lower-level view of what the code is doing than you want, since basic control constructs such as DO
are also implemented as macros. In other words, while it can be educational to see what your macro ultimately expands into, it isn't a very useful view into what your own macros are doing.
96
If the macro expansion is shown all on one line, it's probably because the variable *PRINT- PRETTY*
is NIL
. If it is, evaluating (setf *print- pretty* t)
should make the macro expansion easier to read.
97
This is from http://www.joelonsoftware.com/ articles/LeakyAbstractions.html
. Spolsky's point in the essay is that all abstractions leak to some extent; that is, there are no perfect abstractions. But that doesn't mean you should tolerate leaks you can easily plug.
98
Of course, certain forms are supposed to be evaluated more than once, such as the forms in the body of a do-primes
loop.
99