📝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*
setq
flet
,labels
: similar tolet
but define functions.flet
names can only be references in the body, butlabels
names can be references immediately withinlabels
definitions.macrolet
,symbol-macrolet
function
: gets function object (reader macro:#'
)
Local Flow of Control
block
+return-from
: return from a block/function immediatelyblock
+return-from
work correctly across function boundaries unwinding the stack. (Theblock
label is lexically scoped, not dynamically.)important note: the labels have dynamic extent—you cannot
return-from
a block that is no longer on a stack.
tagbody
+go
: low-level goto constructtagbody
+go
also work across function boundaries unwinding the stack as needed
Unwinding the Stack
catch
andthrow
: are dynamic counterparts ofblock
andreturn-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
locally
the
load-time-value
progv