This section describes functions for testing whether various facts are true or false.
The CL package defines a version of the Common Lisp
(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.
(typep object t)is always true. Likewise, the type symbol
nilstands for nothing at all, and
(typep object nil)is always false.
nullrepresents the symbol
(typep object 'null)is equivalent to
realis a synonym for
fixnumis a synonym for
string-charmatch integers in the range from 0 to 255.
floatp-safepredicate defined by this package rather than
floatp, so it will work correctly even in Emacs versions without floating-point support.
(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
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
float, then integers can be coerced in versions of Emacs that support floats. In all other circumstances,
coercesignals an error.
defmacroin 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 by
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
defmacro*except that optional arguments without explicit defaults use
nilas the "default" default. Some examples:
(deftype null () '(satisfies null)) ; predefined (deftype list () '(or null cons)) ; predefined (deftype unsigned-byte (&optional bits) (list 'integer 0 (if (eq bits '*) bits (1- (lsh 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.
check-type macros also use type
names. See section Conditionals. See section Assertions and Errors. The
merge functions take type-name
arguments to specify the type of sequence to return. See section Sequences.
This package defines two Common Lisp predicates,
eq, except that if a and b are numbers of the same type, it compares them for numeric equality (as if by
eq). This makes a difference only for versions of Emacs that are compiled with floating-point support, such as Emacs 19. Emacs floats are allocated objects just like cons cells, which means that
(eq 3.0 3.0)will not necessarily be true--if the two
3.0s were allocated separately, the pointers will be different even though the numbers are the same. But
(eql 3.0 3.0)will always be true.
The types of the arguments must match, so
(eql 3 3.0) is
Note that Emacs integers are "direct" rather than allocated, which
(eq 3 3) will always be true. Thus
eql behave differently only if floating-point numbers are
involved, and are indistinguishable on Emacs versions that don't
There is a slight inconsistency with Common Lisp in the treatment of
positive and negative zeros. Some machines, notably those with IEEE
standard arithmetic, represent
-0 as distinct
values. Normally this doesn't matter because the standard specifies
(= 0.0 -0.0) should always be true, and this is indeed
what Emacs Lisp and Common Lisp do. But the Common Lisp standard
(eql 0.0 -0.0) and
(equal 0.0 -0.0) should
be false on IEEE-like machines; Emacs Lisp does not do this, and in
fact the only known way to distinguish between the two zeros in Emacs
Lisp is to
format them and check for a minus sign.
equal. In particular, it compares strings case-insensitively, and it compares numbers without regard to type (so that
(equalp 3 3.0)is true). Vectors and conses are compared recursively. All other objects are compared as if by
This function differs from Common Lisp
equalp in several
respects. First, Common Lisp's
equalp also compares
characters case-insensitively, which would be impractical
in this package since Emacs does not distinguish between integers
and characters. In keeping with the idea that strings are less
vector-like in Emacs Lisp, this package's
equalp also will
not compare strings against vectors of integers. Finally, Common
equalp compares hash tables without regard to
ordering, whereas this package simply compares hash tables in
terms of their underlying structure (which means vectors for Lucid
Emacs 19 hash tables, or lists for other hash tables).
Also note that the Common Lisp functions
eql to compare elements, whereas Emacs Lisp follows the
MacLisp tradition and uses
equal for these two functions.
In Emacs, use
assoc* to get functions
eql for comparisons.
Go to the first, previous, next, last section, table of contents.