What are special forms?
In Common Lisp, a special form is a Lisp expression that looks like a function call, i.e., has the form (function-name ...), but is, in fact, treated specially by the Lisp interpreter.
Function calls always work the same way:
- All the arguments, if any, are evaluated.
- The values of the arguments, and only the values are passed to the function, through its formal parameters.
Special forms, on the other hand, have no such regular pattern of behavior. Here are some examples of special forms that violate the above rules:
(quote a)
- The
a
is not evaluated. (if (> x y) a b)
- The first argument is evaluated, but, depending on whether
x
ory
is larger, either the second or third argument will not be evaluated. (let ((x 10)) (* x x))
- Part of the first argument is evaluated, and part is not.
Furthermore,
let
is able to refer to and modifyx
itself, not just the value ofx
. (defun foo (x) (+ x 1))
- None of the arguments to
defun
are evaluated. In fact, neither the function name,foo
, nor the parameter list,(x)
, should ever be evaluated.
Common Lisp comes with a predefined set of special functions,
including and
, cond
, defun
,
let
, or
, and so on.
You can't define your own special functions, but you can do something almost as good, using macros.