Common Lisp the Language, 2nd Edition


next up previous contents index
Next: Numbers Up: Common Lisp the Language Previous: Overview of Syntax

2. Data Types

Common Lisp provides a variety of types of data objects. It is important to note that in Lisp it is data objects that are typed, not variables. Any variable can have any Lisp object as its value. (It is possible to make an explicit declaration that a variable will in fact take on one of only a limited set of values. However, such a declaration may always be omitted, and the program will still run correctly. Such a declaration merely constitutes advice from the user that may be useful in gaining efficiency. See declare.)

In Common Lisp, a data type is a (possibly infinite) set of Lisp objects. Many Lisp objects belong to more than one such set, and so it doesn't always make sense to ask what is the type of an object; instead, one usually asks only whether an object belongs to a given type. The predicate typep may be used to ask whether an object belongs to a given type, and the function type-of returns a type to which a given object belongs.

The data types defined in Common Lisp are arranged into a hierarchy (actually a partial order) defined by the subset relationship. Certain sets of objects, such as the set of numbers or the set of strings, are interesting enough to deserve labels. Symbols are used for most such labels (here, and throughout this book, the word ``symbol'' refers to atomic symbols, one kind of Lisp object, elsewhere known as literal atoms). See chapter 4 for a complete description of type specifiers.

The set of all objects is specified by the symbol t. The empty data type, which contains no objects, is denoted by nil.

old_change_begin
A type called common encompasses all the data objects required by the Common Lisp language. A Common Lisp implementation is free to provide other data types that are not subtypes of common.
old_change_end

change_begin
X3J13 voted in March 1989 (COMMON-TYPE)   to remove the type common (and the predicate commonp) from the language, on the grounds that it has not proved to be useful in practice and that it could be difficult to redefine in the face of other changes to the Common Lisp type system (such as the introduction of CLOS classes).
change_end

The following categories of Common Lisp objects are of particular interest: numbers, characters, symbols, lists, arrays, structures, and functions. There are others as well. Some of these categories have many subdivisions. There are also standard types defined to be the union of two or more of these categories. The categories listed above, while they are data types, are neither more nor less ``real'' than other data types; they simply constitute a particularly useful slice across the type hierarchy for expository purposes.

Here are brief descriptions of various Common Lisp data types. The remaining sections of this chapter go into more detail and also describe notations for objects of each type. Descriptions of Lisp functions that operate on data objects of each type appear in later chapters.

old_change_begin


old_change_end

change_begin
X3J13 voted in June 1988 (FUNCTION-TYPE)   to specify that symbols are not of type function, but are automatically coerced to functions in certain situations (see section 2.13).

X3J13 voted in June 1988 (CONDITION-SYSTEM)   to adopt the Common Lisp Condition System, thereby introducing a new category of data objects:

X3J13 voted in June 1988 (CLOS)   to adopt the Common Lisp Object System, thereby introducing additional categories of data objects:


change_end

These categories are not always mutually exclusive. The required relationships among the various data types are explained in more detail in section 2.15.




next up previous contents index
Next: Numbers Up: Common Lisp the Language Previous: Overview of Syntax


AI.Repository@cs.cmu.edu