📝Common Lisp: special operators
Special operators are forms that are neither functions, nor macros. They provide lower-level building blocks for the rest of the functions and macros.
In Common Lisp, there are 25 special operators.
- Controlling evaluation:
quote,if,progn
- Manipulating the Lexical Environment
let,let*setqflet,labels: similar toletbut define functions.fletnames can only be references in the body, butlabelsnames can be references immediately withinlabelsdefinitions.macrolet,symbol-macroletfunction: gets function object (reader macro:#')
- Local Flow of Control
block+return-from: return from a block/function immediatelyblock+return-fromwork correctly across function boundaries unwinding the stack. (Theblocklabel is lexically scoped, not dynamically.)- important note: the labels have dynamic extent—you cannot
return-froma block that is no longer on a stack.
- important note: the labels have dynamic extent—you cannot
tagbody+go: low-level goto constructtagbody+goalso work across function boundaries unwinding the stack as needed
- Unwinding the Stack
catchandthrow: are dynamic counterparts ofblockandreturn-from- mostly unused because of condition system
unwind-protect: ensure some code is always executed if stack is unwinding(unwind-protect protected-form cleanup-form*)
- Multiple Values
multiple-value-call(see Common Lisp: multiple values)
eval-when;; Basic form: (eval-when (situation*) body-form*)Possible situations:
:compile-toplevel,:load-toplevel, and:execute- other
locallytheload-time-valueprogv