A type specifier is an expression that denotes a type. A type represents a set of possible values. Type specifiers can be classified into primitive types and compound types.
Type specifiers are in use for several purposes, including: documenting
function interfaces through declaration (see declare
フォーム), specifying
structure slot values (see Structures in Common Lisp Extensions for
GNU Emacs Lisp), type-checking through cl-the
(see Declarations in Common Lisp Extensions for GNU Emacs Lisp), and
others.
Primitive types specifiers are the basic types (i.e. not composed by other type specifiers).
Built-in primitive types (like integer
, float
, string
etc.) are listed in Emacs Lispオブジェクトの型階層.
Compound types serve the purpose of defining more complex or precise type specifications by combining or modifying simpler types.
List of compound type specifiers:
(or type-1 … type-n)
The or
type specifier describes a type that satisfies at least one of
the given types.
(and type-1 … type-n)
Similarly the and
type specifier describes a type that satisfies all
of the given types.
(not type)
The not
type specifier defines any type except the specified one.
(member value-1 … value-n)
The member
type specifier allows to specify a type that includes only
the explicitly listed values.
(function (arg-1-type … arg-n-type) return-type)
The function
type specifier is used to describe the argument types
and the return type of a function. Argument types can be interleaved with
symbols &optional
and &rest
to match the function’s arguments
(see 引数リストの機能).
The type specifier represent a function whose first parameter is of type
symbol
, the second optional parameter is of type float
, and
which returns an integer
:
(function (symbol &optional float) integer)
(integer lower-bound upper-bound)
The integer
type specifier can also be used as a compound type
specifier to define a subset of integer values by specifying a range. This
allows to precisely control which integers are valid for a given type.
lower-bound is the minimum integer value in the range and
upper-bound the maximum. You can use *
instead of the lower or
upper bound to indicate no limit.
The following represents all integers from -10 to 10:
(integer -10 10)
The following represents the single value of 10:
(integer 10 10)
The following represents all the integers from negative infinity to 10:
(integer * 10)