Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

What would be an example of an anaphoric conditional in Lisp? Please explain the code as well.

share|improve this question
1  
I am only familiar with the term "anaphoric" as it pertains to natural languages -- for example, a pronoun can be considered an anaphoric reference to a previously mentioned noun. "John is a programmer. He works for Google." In this example, "he" is an anaphoric reference to "John". So I think you need to explain what an "anaphoric conditional" means in the context of Lisp programming -- it's not a commonly used term. –  Jim Lewis Oct 13 '10 at 1:42
 
@Jim_Lewis: Here's explanation what an "anaphoric conditional" means in the context of Lisp programming: weblogs.java.net/blog/2006/06/29/… –  blunders Oct 13 '10 at 1:52
2  
@Jim Lewis: Unsurprisingly, that's precisely what anaphoric means when referring to macros. See my answer for links and example. –  Greg Hewgill Oct 13 '10 at 1:55
 
Thanks for the links...I get it now! You learn something new every day around here... –  Jim Lewis Oct 13 '10 at 3:25
add comment

2 Answers

up vote 3 down vote accepted

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.

share|improve this answer
 
@Rainer_Joswig: Wow, thanks -- that was amazingly clear to me. Again, thank you!! –  blunders Oct 13 '10 at 12:05
 
@Rainer_Joswig: From your experience, what has been the best way to learn LISP for you? –  blunders Oct 13 '10 at 12:07
add comment

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).

share|improve this answer
 
@Greg Hewgill: Thanks, still sort of lost in Paul Graham's code, but it's fun to process. –  blunders Oct 13 '10 at 2:11
2  
@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 Oct 13 '10 at 2:19
 
@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: stackoverflow.com/questions/3920046/… –  blunders Oct 13 '10 at 2:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.