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:

  1. All the arguments, if any, are evaluated.
  2. 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 or y 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 modify x itself, not just the value of x.
(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.
In short, the rules for evaluating a special form depend on the particular special function being called.

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.

Faculty: Chris Riesbeck
Time: Monday, Wednesday, Friday: 1pm - 2pm
Location:Annenberg G15

Contents

Important Links