Type Predicates
Function: cl-typep object type
Check if object is of type type, where type is a (quoted) type name of the sort used by Common Lisp. For example, (cl-typep foo 'integer) is equivalent to (integerp foo).
The type argument to the above function is either a symbol or a list beginning with a symbol.
- If the type name is a symbol, Emacs appends ‘
-p’ to the symbol name to form the name of a predicate function for testing the type. (Built-in predicates whose names end in ‘p’ rather than ‘-p’ are used when appropriate.) - The type symbol
tstands for the union of all types.(cl-typep object t)is always true. Likewise, the type symbolnilstands for nothing at all, and(cl-typep object nil)is always false. - The type symbol
nullrepresents the symbolnil. Thus(cl-typep object 'null)is equivalent to(null object). - The type symbol
atomrepresents all objects that are not cons cells. Thus(cl-typep object 'atom)is equivalent to(atom object). - The type symbol
realis a synonym fornumber, andfixnumis a synonym forinteger. - The type symbols
characterandstring-charmatch integers in the range from 0 to 255. - The type list
(integer low high)represents all integers betweenlowandhigh, inclusive. Either bound may be a list of a single integer to specify an exclusive limit, or a*to specify no limit. The type(integer * *)is thus equivalent tointeger. - Likewise, lists beginning with
float,real, ornumberrepresent numbers of that type falling in a particular range. - Lists beginning with
and,or, andnotform combinations of types. For example,(or integer (float 0 *))represents all objects that are integers or non-negative floats. - Lists beginning with
memberorcl-memberrepresent objectseqlto any of the following values. For example,(member 1 2 3 4)is equivalent to(integer 1 4), and(member nil)is equivalent tonull. - Lists of the form
(satisfies predicate)represent all objects for whichpredicatereturns true when called with that object as an argument.
The following function and macro (not technically predicates) are related to cl-typep.
Function: cl-coerce object type
This function attempts to convert object to the specified type. If object is already of that type as determined by cl-typep, it is simply returned. Otherwise, certain types of conversions will be made: If type is any sequence type (string, list, etc.) then object will be converted to that type if possible. If type is character, then strings of length one and symbols with one-character names can be coerced. If type is float, then integers can be coerced in versions of Emacs that support floats. In all other circumstances, cl-coerce signals an error.