views:

115

answers:

2

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
**@Greg Hewgill:** Thanks, still sort of lost in Paul Graham's code, but it's fun to process.
blunders
@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
**@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
+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
**@Rainer_Joswig:** Wow, thanks -- that was amazingly clear to me. Again, thank you!!
blunders
**@Rainer_Joswig:** From your experience, what has been the best way to learn LISP for you?
blunders