3. Predicates

A predicate is a function which tests for some condition involving its arguments and returns the symbol t if the condition is true, or the symbol nil if it is not true. By convention, the names of predicates usually end in the letter "p" (which stands for "predicate"). (See [section on naming conventions]).

The following predicates are for testing data types. These predicates return t if the argument is of the type indicated by the name of the function, nil if it is of some other type.

symbolp arg

symbolp returns t if its argument is a symbol, otherwise nil .

nsymbolp arg
nsymbolp returns nil if its argument is a symbol, otherwise t .
listp arg

listp returns t if its argument is a cons, otherwise nil . (listp nil) is nil even though nil is the empty list.

nlistp arg
nlistp returns t if its argument is anything besides a cons, otherwise nil . This is the recommended predicate for terminating iterations or recursions on lists. It is, in fact, identical to atom .
atom arg

The predicate atom returns t if its argument is not a cons, otherwise nil .

fixp arg
fixp returns t if its argument is a fixnum or a bignum, otherwise nil .
floatp arg
floatp returns t if its argument is a flonum or a small flonum, otherwise nil .
small-floatp arg
small-floatp returns t if arg is a small flonum, otherwise nil .
bigp arg
bigp returns t if arg is a bignum, otherwise nil .
numberp arg

numberp returns t if its argument is any kind of number, otherwise nil .

stringp arg

stringp returns t if its argument is a string, otherwise nil .

arrayp arg

arrayp returns t if its argument is an array, otherwise nil . Note that strings are arrays.

subrp arg
subrp returns t if its argument is any compiled code object, otherwise nil . The Lisp Machine system doesn't use the term "subr", but the name of this function comes from Maclisp.
closurep arg

closurep returns t if its argument is a closure, otherwise nil .

locativep arg

locativep returns t if its argument is a locative, otherwise nil .

typep arg
typep is not really a predicate, but it is explained here because it is used to determine the datatype of an object. It returns a symbol describing the type of its argument, one of the following:
:symbolA symbol.
:fixnumA fixnum.
:flonumA flonum.
:small-flonumA small flonum.
:bignumA bignum.
:listA cons.
:stringA string.
:arrayAn array that is not a string.
:randomAny built-in data type that does not fit into one of the above categories.
foo An object of user-defined data-type foo (any symbol). See Named Structures, this link.
See also data-type , LINK:(data-type-fun).