Anaphoric macro
Encyclopedia
An anaphoric macro is a type of programming macro that deliberately captures some form supplied to the macro which may be referred to by an anaphor (an expression referring to another). Anaphoric macros first appeared in Paul Graham's On Lisp
and their name is a reference to linguistic anaphora
—the use of words as a substitute for preceding words.
Here is an example that sums the value of non-nil elements, where it refers to the values of elements that do not equal nil:
Here it is bound to the output of (and (> number 3) number) when true, collecting numbers larger than 3:
Anther example is an anaphoric version of the λ-function which binds the function itself to the anaphor self, allowing it to recurse
:
On Lisp
On Lisp: Advanced Techniques for Common Lisp is a book by Paul Graham on macro programming in Common Lisp. It is currently out of print, but can be freely downloaded as a pdf.-External links:**Free versions of "On Lisp"******...
and their name is a reference to linguistic anaphora
Anaphora (linguistics)
In linguistics, anaphora is an instance of an expression referring to another. Usually, an anaphoric expression is represented by a pro-form or some other kind of deictic--for instance, a pronoun referring to its antecedent...
—the use of words as a substitute for preceding words.
Examples
The loop macro in ANSI Common Lisp is anaphoric in that it binds it to the result of the test expression in a clause.Here is an example that sums the value of non-nil elements, where it refers to the values of elements that do not equal nil:
Here it is bound to the output of (and (> number 3) number) when true, collecting numbers larger than 3:
Defining anaphoric macros
One example is an anaphoric version of the if-then-else construct which introduces an anaphor it which is bound to the result of the test clause:Anther example is an anaphoric version of the λ-function which binds the function itself to the anaphor self, allowing it to recurse
Recursion (computer science)
Recursion in computer science is a method where the solution to a problem depends on solutions to smaller instances of the same problem. The approach can be applied to many types of problems, and is one of the central ideas of computer science....
:
External links
- Chapter 14. Anaphoric Macros from On LispOn LispOn Lisp: Advanced Techniques for Common Lisp is a book by Paul Graham on macro programming in Common Lisp. It is currently out of print, but can be freely downloaded as a pdf.-External links:**Free versions of "On Lisp"******...
by Paul GrahamPaul GrahamPaul Graham is a programmer, venture capitalist, and essayist. He is known for his work on Lisp, for co-founding Viaweb , and for co-founding the Y Combinator seed capital firm... - Anaphora — an anaphoric macro collection