simplify: "* (macroexpand '(nif x 'pos 'zero 'neg)) (LET ((#:G1605 X)) (COND ((PLUSP…
- User
simplify: "* (macroexpand '(nif x 'pos 'zero 'neg))
(LET ((#:G1605 X)) (COND ((PLUSP #:G1605) 'POS) ((ZEROP #:G1605) 'ZERO) (T 'NEG))) T
The name g disappears in the macro expansion. Because g was only bound in our expander environment, the name given to such a variable is irrelevant with respect to capture in the expansions. All occurrences of g have, in the expansion, been replaced by a symbol with a print name of G1605. It is prefixed by #: because the symbol is not interned in any package—it is a gensym. When printing out forms, it is necessary to prefix gensyms in such a way because we want lisp to break if we ever use (evaluate) this form after reading it back in again. We want lisp to break because we can't know by looking at the print names of two gensyms if they should be eq or not—that is their purpose. Lisp breaks in an interesting way: because each time a #: symbol is read in a new symbol is created, and because (eq '#:a '#:a) is never true, the inner #:G1605 symbols in the above expansion do not refer to the binding created by the let form so lisp considers the expression to have a free variable, indicating to us that a form with gensyms was read back in again."
- Assistant
The explanation provided describes how Lisp macros work, specifically how gensyms are used to avoid variable capture in macro expansions. Let me break it down for you:
-
Macro Expansion Process:
The macro(nif x 'pos 'zero 'neg)expands to aletbinding using a temporary variable (gensym) and acondexpression that checks the value ofx.
-
- User
explain 5. Lisp's Way of Handling It" more i having a hard time
- Assistant