www.delorie.com/gnu/docs/elisp-manual-21/elisp_81.html   search  
 
Buy the book!


GNU Emacs Lisp Reference Manual

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.3 Predicates on 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.)

Function: consp object
This function returns t if object is a cons cell, nil otherwise. nil is not a cons cell, although it is a list.

Function: atom object
This function returns t if object is an atom, nil otherwise. All objects except cons cells are atoms. The symbol nil is an atom and is also a list; it is the only Lisp object that is both.

 
(atom object) == (not (consp object))

Function: listp object
This function returns t if object is a cons cell or nil. Otherwise, it returns nil.

 
(listp '(1))
     => t
(listp '())
     => t

Function: nlistp object
This function is the opposite of listp: it returns t if object is not a list. Otherwise, it returns nil.

 
(listp object) == (not (nlistp object))

Function: null object
This function returns t if object is nil, and returns nil otherwise. This function is identical to not, but as a matter of clarity we use null when object is considered a list and not when it is considered a truth value (see not in 10.3 Constructs for Combining Conditions).

 
(null '(1))
     => nil
(null '())
     => t


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003