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. 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 loop macro in ANSI Common Lisp is anaphoric in binding 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:


;; ⇒ 16

Here it is bound to the output of when true, collecting numbers larger than 3:

; IT refers to.
;; ⇒

Defining anaphoric macros

One example is an anaphoric version of the if-then-else construct, which introduces an anaphor it, bound to the result of the test clause:


`)
))


)
;; ⇒ "9 does not equal NIL."

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


`)
#'self))
;; Factorial function defined recursively where `self' refers to the alambda function


1
))