Please explain the code as well. Thanks!
+7
A:
Paul Graham's On Lisp has a chapter on Anaphoric Macros.
Essentially, it's a shorthand way of writing statements that avoids repeating code. For example, compare:
(let ((result (big-long-calculation)))
(if result
(foo result)))
and
(if (big-long-calculation)
(foo it))
where it
is a special name that refers to whatever was just calculated in (big-long-calculation)
.
Greg Hewgill
2010-10-13 01:54:01
**@Greg Hewgill:** Thanks, still sort of lost in Paul Graham's code, but it's fun to process.
blunders
2010-10-13 02:11:11
@blunders: Indeed. Anaphoric macros probably isn't the best place to start, unless you're already very familiar with the different styles of macros in Lisp. On Lisp is a great read.
Greg Hewgill
2010-10-13 02:19:41
**@Greg Hewgill:** Agree. I've scanned a few LISP books, mainly The Little Schemer, and the like. "Anaphoric conditional" randomly came up in doing research for this question: http://stackoverflow.com/questions/3920046/is-it-common-for-a-language-to-evalute-undefined-as-equal-to-false-if-so-why-is
blunders
2010-10-13 02:26:19
+3
A:
An example is the Common Lisp LOOP:
(loop for item in list
when (general-predicate item)
collect it)
The variable IT has the value of the test expression. This is a feature of the ANSI Common Lisp LOOP facility.
Example:
(loop for s in '("sin" "Sin" "SIN")
when (find-symbol s)
collect it)
returns
(SIN)
because only "SIN" is a name for an existing symbol, here the symbol SIN. In Common Lisp symbol names have internally uppercase names by default.
Rainer Joswig
2010-10-13 09:13:18