Logical Operators

Predicates can be combined by the logical operators AND, OR, and NOT.

(NOT x) returns T if x is NIL; otherwise, it returns NIL. NOT is therefore the same as NULL.

(AND x1 ... xn) evaluates each of x1 ... xn in order. As soon as any xi returns NIL, AND returns NIL without evaluating any remaining x's. If every xi returns a non- NIL value, the value of AND is the value of xn.


(DEFUN SAFE-SQRT (X)
  (AND (NUMBERP X)
       (NOT (MINUSP X))
       (SQRT X)) )

(OR x1 ... xn) evaluates each of x1 ... xn in order. As soon as any xi returns a non- NIL value, OR returns that value without evaluating any remaining x's. If every xi returns NIL, the value of OR is NIL.


(OR (>  CASH 100) (PRINT ``Get money.''))

Contents    Page-10    Prev    Next    Page+10    Index