and and or are functions but not predicates since they may return values other than t or nil. Each evaluates its arguments in the order they appear, but only enough arguments to provide a definitive result are evaluated. So, some arguments to and and to or may not be evaluated at all.
and returns nil as soon as it finds an argument which evaluates to nil; otherwise it returns the value of its last argument. For example:
In the example immediately above, the expression (setf y 'hello) is never evaluated since (rest '(a)) returns nil. You can check this out by evaluating y directly:> (and 1 2 3 4) 4 > (and 1 (cons 'a '(b)) (rest '(a)) (setf y 'hello)) NIL
or returns the result of its first non-nil argument, and does not evaluate the rest of its arguments. If all the arguments evaluate to nil, then or returns nil. Examples:> y 49
Once again, you will see that y's value is unchanged by these examples.> (or nil nil 2 (setf y 'goodbye)) 2 > (or (rest '(a)) (equal 3 4)) NIL
© Colin Allen & Maneesh Dhagat