Next: List Elements, Previous: Lists as Boxes, Up: Lists
The following predicates test whether a Lisp object is an atom, is a
cons cell or is a list, or whether it is the distinguished object
nil
. (Many of these predicates can be defined in terms of the
others, but they are used so often that it is worth having all of them.)
This function returns
t
if object is a cons cell,nil
otherwise.nil
is not a cons cell, although it is a list.
This function returns
t
if object is an atom,nil
otherwise. All objects except cons cells are atoms. The symbolnil
is an atom and is also a list; it is the only Lisp object that is both.(atom object) == (not (consp object))
This function returns
t
if object is a cons cell ornil
. Otherwise, it returnsnil
.(listp '(1)) => t (listp '()) => t
This function is the opposite of
listp
: it returnst
if object is not a list. Otherwise, it returnsnil
.(listp object) == (not (nlistp object))
This function returns
t
if object isnil
, and returnsnil
otherwise. This function is identical tonot
, but as a matter of clarity we usenull
when object is considered a list andnot
when it is considered a truth value (seenot
in Combining Conditions).(null '(1)) => nil (null '()) => t