|
Practical Common LispIf you macro-expand the with-gensyms form in the new definition of do-primes, you should see something like this: (let ((ending-value-name (gensym))) `(do ((,var (next-prime ,start) (next-prime (1+ ,var))) (,ending-value-name ,end)) ((> ,var ,ending-value-name)) ,@body)) Looks good. While this macro is fairly trivial, it's important to keep clear about when the different macros are expanded: when you compile the DEFMACRO of do-primes, the with-gensyms form is expanded into the code just shown and compiled. Thus, the compiled version of do-primes is just the same as if you had written the outer LET by hand. When you compile a function that uses do-primes, the code generated by with-gensyms runs generating the do-primes expansion, but with-gensyms itself isn't needed to compile a do-primes form since it has already been expanded, back when do-primes was compiled. Another classic macro-writing MACRO: ONCE-ONLY Another classic macro-writing macro is once-only, which is used to generate code that evaluates certain macro arguments once only and in a particular order ...» |
Код для вставки книги в блог HTML
phpBB
текст
|
|