next up previous
Next: 2.3 Functions Up: 2. THE LISP INTERPRETER Previous: 2.1 Variables

2.2 Constants

It is sometimes assumed that a constant stands for itself as opposed to a variable which stands for something else. This is not a very workable concept, since the student who is learning calculus is taught to represent constants by a, b, c ...and variables by x, y, z .... It seems more reasonable to say that one variable is more nearly constant than another if it is bound at a higher level and changes value less frequently.

In LISP, a variable remains bound within the scope of the LAMBDA that binds it. When a variable always has a certain value regardless of the current a-list, it will be called a constant. This is accomplished by means of the property list2.1 (p-list) of the variable symbol. Every atomic symbol has a p-list. When the p-list contains the indicator APVAL, then the symbol is a constant and the next item on the list is the value. eval searches p-lists before a-lists when evaluating variables, thus making it possible to set constants.

Constants can be made by the programmer. To make the variable X always stand for (A B C D), use the pseudo-function cset.

cset[X;(A B C D)]

An interesting type of constant is one that stands for itself. NIL is an example of this. It can be evaluated repeatedly and will still be NIL. T, F. NIL, and other constants cannot be used as variables.


next up previous
Next: 2.3 Functions Up: 2. THE LISP INTERPRETER Previous: 2.1 Variables