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
The type argument to the above function is either a symbol or a list beginning with a symbol.
tstands for the union of all types.
(cl-typep object t)is always true. Likewise, the type symbol
nilstands for nothing at all, and
(cl-typep object nil)is always false.
nullrepresents the symbol
(cl-typep object 'null)is equivalent to
atomrepresents all objects that are not cons cells. Thus
(cl-typep object 'atom)is equivalent to
realis a synonym for
fixnumis a synonym for
string-charmatch integers in the range from 0 to 255.
(integer low high)represents all integers between low and high, 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 to
numberrepresent numbers of that type falling in a particular range.
notform combinations of types. For example,
(or integer (float 0 *))represents all objects that are integers or non-negative floats.
eqlto any of the following values. For example,
(member 1 2 3 4)is equivalent to
(integer 1 4), and
(member nil)is equivalent to
(satisfies predicate)represent all objects for which predicate returns true when called with that object as an argument.
The following function and macro (not technically predicates) are
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
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
then integers can be coerced in versions of Emacs that support
floats. In all other circumstances,
cl-coerce signals an
This macro defines a new type called name. It is similar
defmacro in many ways; when name is encountered
as a type name, the body forms are evaluated and should
return a type specifier that is equivalent to the type. The
arglist is a Common Lisp argument list of the sort accepted
cl-defmacro. The type specifier ‘(name args…)’
is expanded by calling the expander with those arguments; the type
symbol ‘name’ is expanded by calling the expander with
no arguments. The arglist is processed the same as for
cl-defmacro except that optional arguments without explicit
* instead of
nil as the “default”
default. Some examples:
(cl-deftype null () '(satisfies null)) ; predefined (cl-deftype list () '(or null cons)) ; predefined (cl-deftype unsigned-byte (&optional bits) (list 'integer 0 (if (eq bits '*) bits (1- (ash 1 bits))))) (unsigned-byte 8) ≡ (integer 0 255) (unsigned-byte) ≡ (integer 0 *) unsigned-byte ≡ (integer 0 *)
The last example shows how the Common Lisp
type specifier could be implemented if desired; this package does
unsigned-byte by default.
cl-typecase (see Conditionals) and
(see Assertions and Errors) macros also use type names. The
cl-merge functions take type-name
arguments to specify the type of sequence to return. See Sequences.