my-server
← Wiki

Anaphoric macro

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.

Examples

The <code>loop</code> macro in ANSI Common Lisp is anaphoric in binding, where the <code>it</code> expression refers to the result of the test expression in a clause.

Here is an example that sums the value of non-<code>nil</code> elements, where <code>it</code> refers to the values of elements that do not equal <code>nil</code>:

Here <code>it</code> is bound to the output of <code>(and (> number 3) number)</code> 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 <code>it</code>, bound to the result of the test clause:

Another example is an anaphoric version of the λ-function, which binds the function itself to the anaphor <code>self</code>, allowing it to recur:

See also

References

External links