What would be an example of an anaphoric conditional in Lisp? Please explain the code as well.
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)
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With