next up previous
Next: 4. ARITHMETIC IN LISP Up: 3. EXTENSION OF THE Previous: 3.2 Logical Connectives

3.3 Predicates and Truth in LISP

Although the rule for translating M-expressions into S-expressions states that T is (QUOTE T), it was stated that in the system one must always write T instead. Similarly, one must write F rather than (QUOTE F). The programmer may either accept this rule blindly or understand the following Humpty-Dumpty semantics.

In the LISP programming system there are two atomic symbols that represent truth and falsity respectively. These two atomic symbols are *T* and NIL. It is these symbols rather than T and F that are the actual value of all predicates in the system. This s mainly a coding convenience.

The atomic symbols T and F have APVAL's whose values are *T* and NIL, respectively. The symbols T and F for constant predicates will work because:

        eval[T;NIL]=*T* 
        eval[F;NIL]=NIL

The forms (QUOTE *T*) and (QUOTE NIL) will also work because

        eval[(QUOTE *T*);NIL]=*T* 
        eval[(QUOTE NIL);NIL]=NIL

*T* and NIL both have APVAL's that point to themselves Thus *T* and NIL are also acceptable because

        eval[*T*;NIL]=*T* 
        eval[NIL;NIL]=NIL

But

        eval[(QUOTE F);NIL]=F

which is wrong and this is why (QUOTE F) will not work. Note that

        eval[(QUOTE T);alist]=T

which is wrong but will work for a different reason that will be explained in the paragraph after next.

There is no formal distinction between a function and a predicate in LISP. A predicate can be defined as a function whose value is either *T* or NIL. This is true of all predicates in the System.

One may use a form that is not a predicate in a location in which a predicate is called for, such as in the p position of a conditional expression, or as an argument of a logical predicate. Semantically, any S-expression that is not NIL will be regarded as truth in such a case. One consequence of this is that the predicates null and not are identical. Another consequence is that (QUOTE T) or (QUOTE X) is equivalent to T as a constant predicate.

The predicate eq has the following behavior

1. If its arguments are different, the value of eq is NIL.

2. If its arguments are both the same atomic symbol, its value is *T*.

3. If its arguments are both the same, but are not atomic, then the value is *T* or NIL depending upon whether the arguments are identical in their representation in core memory.

4. The value of eq is always *T* or NIL. It is never undefined even if its arguments are bad.


next up previous
Next: 4. ARITHMETIC IN LISP Up: 3. EXTENSION OF THE Previous: 3.2 Logical Connectives