\input macros \drafttrue \tolerance=2500 \def\bookline{\CLOS\ Specification} \def\chapline{Programmer Interface Concepts} \def\newpage{\vfill\eject} \beginChapter 1.{Common Lisp Object System Specification}% {Programmer Interface Concepts}{Programmer Interface Concepts} Authors: Daniel G. Bobrow, Linda G. DeMichiel, Richard P. Gabriel,\hfil\break Sonya E. Keene, Gregor Kiczales, and David A. Moon. Draft Dated: June 15, 1988\hfil\break All Rights Reserved The distribution and publication of this document are not restricted. In order to preserve the integrity of the specification, any publication or distribution must reproduce this document in its entirety, preserve its formatting, and include this title page. For information about obtaining the sources for this document, send an Internet message to common-lisp-object-system-specification-request@sail.stanford.edu. The authors wish to thank Patrick Dussud, Kenneth Kahn, Jim Kempf,\hfil\break Larry Masinter, Mark Stefik, Daniel L. Weinreb, and Jon L White\hfil\break for their contributions to this document. \vskip 2pc At the X3J13 meeting on June 15, 1988, the following motion was adopted: ``The X3J13 Committee hereby accepts chapters 1 and 2 of the Common Lisp Object System, as defined in document 88-002R, for inclusion in the Common Lisp language being specified by this committee. Subsequent changes will be handled through the usual editorial and cleanup processes.'' \endTitlePage \beginSection{Introduction} The \CLOS\ is an object-oriented extension to Common Lisp as defined in {\it Common Lisp: The Language}, by Guy L. Steele Jr. It is based on generic functions, multiple inheritance, declarative method combination, and a meta-object protocol. The first two chapters of this specification present a description of the standard Programmer Interface for the \CLOS. The first chapter contains a description of the concepts of the \CLOS, and the second contains a description of the functions and macros in the \CLOS\ Programmer Interface. The chapter ``The \CLOS\ Meta-Object Protocol'' describes how the \CLOS\ can be customized. The fundamental objects of the \CLOS\ are classes, instances, generic functions, and methods. A {\bit class\/} object determines the structure and behavior of a set of other objects, which are called its {\bit instances}. Every Common Lisp object is an {\bit instance\/} of a class. The class of an object determines the set of operations that can be performed on the object. A {\bit generic function\/} is a function whose behavior depends on the classes or identities of the arguments supplied to it. A generic function object contains a set of methods, a lambda-list, a method combination type, and other information. The {\bit methods} define the class-specific behavior and operations of the generic function; a method is said to {\bit specialize\/} a generic function. When invoked, a generic function executes a subset of its methods based on the classes of its arguments. A generic function can be used in the same ways that an ordinary function can be used in Common Lisp; in particular, a generic function can be used as an argument to {\bf funcall} and {\bf apply} and can be given a global or a local name. A {\bit method\/} is an object that contains a method function, a sequence of {\bit parameter specializers\/} that specify when the given method is applicable, and a sequence of {\bit qualifiers\/} that is used by the {\bit method combination\/} facility to distinguish among methods. Each required formal parameter of each method has an associated parameter specializer, and the method will be invoked only on arguments that satisfy its parameter specializers. The method combination facility controls the selection of methods, the order in which they are run, and the values that are returned by the generic function. The \CLOS\ offers a default method combination type and provides a facility for declaring new types of method combination. \endSection%{Introduction} \beginSection{Error Terminology} The terminology used in this document to describe erroneous situations differs from the terminology used in {\it Common Lisp: The Language}, by Guy L. Steele Jr. This terminology involves {\bit situations}; a situation is the evaluation of an expression in some specific context. For example, a situation might be the invocation of a function on arguments that fail to satisfy some specified constraints. In the specification of the \CLOS, the behavior of programs in all situations is described, and the options available to the implementor are defined. No implementation is allowed to extend the syntax or semantics of the \OS\ except as explicitly defined in the \OS\ specification. In particular, no implementation is allowed to extend the syntax of the \OS\ in such a way that ambiguity between the specified syntax of \OS\ and those extensions is possible. ``When situation $S$ occurs, an error is signaled.'' This terminology has the following meaning: \beginlist \item{\bull} If this situation occurs, an error will be signaled in the interpreter and in code compiled under all compiler safety optimization levels. \item{\bull} Valid programs may rely on the fact that an error will be signaled in the interpreter and in code compiled under all compiler safety optimization levels. \item{\bull} Every implementation is required to detect such an error in the interpreter and in code compiled under all compiler safety optimization levels. \endlist ``When situation $S$ occurs, an error should be signaled.'' This terminology has the following meaning: \beginlist \item{\bull} If this situation occurs, an error will be signaled at least in the interpreter and in code compiled under the safest compiler safety optimization level. \item{\bull} Valid programs may not rely on the fact that an error will be signaled. \item{\bull} Every implementation is required to detect such an error at least in the interpreter and in code compiled under the safest compiler safety optimization level. \item{\bull} When an error is not signaled, the results are undefined (see below). \endlist ``When situation $S$ occurs, the results are undefined.'' This terminology has the following meaning: \beginlist \item{\bull} If this situation occurs, the results are unpredictable. The results may range from harmless to fatal. \item{\bull} Implementations are allowed to detect this situation and signal an error, but no implementation is required to detect the situation. \item{\bull} No valid program may depend on the effects of this situation, and all valid programs are required to treat the effects of this situation as unpredictable. \endlist ``When situation $S$ occurs, the results are unspecified.'' This terminology has the following meaning: \beginlist \item{\bull} The effects of this situation are not specified in the \OS, but the effects are harmless. \item{\bull} Implementations are allowed to specify the effects of this situation. \item{\bull} No portable program can depend on the effects of this situation, and all portable programs are required to treat the situation as unpredictable but harmless. \endlist ``The \CLOS\ may be extended to cover situation $S$\negthinspace.'' The meaning of this terminology is that an implementation is free to treat situation $S$ in one of three ways: \beginlist \item{\bull} When situation $S$ occurs, an error is signaled at least in the interpreter and in code compiled under the safest compiler safety optimization level. \item{\bull} When situation $S$ occurs, the results are undefined. \item{\bull} When situation $S$ occurs, the results are defined and specified. \endlist In addition, this terminology has the following meaning: \beginlist \item{\bull} No portable program can depend on the effects of this situation, and all portable programs are required to treat the situation as undefined. \endlist ``Implementations are free to extend the syntax $S$\negthinspace.'' This terminology has the following meaning: \beginlist \item{\bull} Implementations are allowed to define unambiguous extensions to syntax $S$\negthinspace. \item{\bull} No portable program can depend on this extension, all portable programs are required to treat the syntax as meaningless. \endlist The \CLOS\ specification may disallow certain extensions while allowing others. \endSection%{Error Terminology} \beginSection{Classes} A {\bit class\/} is an object that determines the structure and behavior of a set of other objects, which are called its {\bit instances}. A class can inherit structure and behavior from other classes. A class whose definition refers to other classes for the purpose of inheriting from them is said to be a {\bit subclass\/} of each of those classes. The classes that are designated for purposes of inheritance are said to be {\bit superclasses\/} of the inheriting class. A class can have a {\bit name}. The function {\bf class-name} takes a class object and returns its name. The name of an anonymous class is {\bf nil}. A symbol can {\bit name\/} a class. The function {\bf find-class} takes a symbol and returns the class that the symbol names. A class has a {\bit proper name\/} if the name is a symbol and if the name of the class names that class. That is, a class~$C$ has the {\bit proper name\/}~$S$ if $S=$ {\tt (class-name $C$)} and $C=$ {\tt (find-class $S$)}. Notice that it is possible for {\tt (find-class $S\sub 1$)} $=$ {\tt (find-class $S\sub 2$)} and $S\sub 1\neq S\sub 2$. If $C=$ {\tt (find-class $S$)}, we say that $C$ is the {\bit class named} $S$. A class $C\sub{1}$ is a {\bit direct superclass\/} of a class $C\sub{2}$ if $C\sub{2}$ explicitly designates $C\sub{1}$ as a superclass in its definition. In this case $C\sub{2}$ is a {\bit direct subclass\/} of $C\sub{1}$. A class $C\sub{n}$ is a {\bit superclass\/} of a class $C\sub{1}$ if there exists a series of classes $C\sub{2},\ldots,C\sub{n-1}$ such that $C\sub{i+1}$ is a direct superclass of $C\sub{i}$ for $1 \leq i