not
not Function
Syntax:
not x → boolean
Arguments and Values:
x—a generalized boolean (i.e., any object).
boolean—a boolean.
Description:
Returns t if x is false; otherwise, returns nil.
Examples:
(not nil) → T
(not ’()) → T
(not (integerp ’sss)) → T
(not (integerp 1)) → NIL
(not 3.7) → NIL
(not ’apple) → NIL
See Also:
nullNotes:
not is intended to be used to invert the ‘truth value’ of a boolean (or generalized boolean) whereas null is intended to be used to test for the empty list. Operationally, not and null compute the same result; which to use is a matter of style.
Expanded Reference: not
Basic boolean negation
not returns T if its argument is NIL, and NIL otherwise.
(not nil) → T
(not t) → NIL
Any non-NIL value is truthy
In Common Lisp, everything except NIL is considered true. not reflects this.
(not 42) → NIL
(not "hello") → NIL
(not 'apple) → NIL
(not '(1 2 3)) → NIL
Using not with predicates
not is commonly used to invert the result of a predicate call.
(not (integerp 5)) → NIL
(not (integerp "hello")) → T
(not (> 3 5)) → T
(not (member 'x '(a b c))) → T
not vs null
not and null compute the same result but express different intent. Use not for boolean logic and null for testing empty lists.
;; Boolean logic intent
(not (evenp 3)) → T
;; Empty list testing intent
(null '()) → T
(null '(a b)) → NIL
;; They are functionally identical
(eq (not '()) (null '())) → T
Chaining with not
not can be used to coerce a generalized boolean to a strict boolean (T or NIL).
(not (not 42)) → T
(not (not nil)) → NIL
(not (not (member 'b '(a b c)))) → T