perm filename CONCEP.1[CLS,LSP] blob sn#825853 filedate 1986-10-27 generic text, type T, neo UTF8
\input macros
\def\bookline{\CLOS\  Specification}
\def\chapline{Basic User Interface Concepts}

\beginChapter 1.{Common Lisp Object System Specification}%
{Basic User Interface Concepts}{Basic User Interface Concepts}

Contributors to this document include Daniel G. Bobrow, Linda G.
DeMichiel,\break Richard P. Gabriel, Kenneth Kahn, Sonya E. Keene,
Gregor Kiczales, Larry\break Masinter, David A. Moon, Mark Stefik, and
Daniel L. Weinreb.

Comments and suggestions on this document are encouraged.
Changes will be incorporated over the next several months.
This text will be made available to the X3J13 Committee for the
Common Lisp Standards effort.



This chapter describes the standard user interface for object-oriented
programming in the \CLOS.  The chapter ``Meta-Object
Protocol'' describes how the \CLOS\  can be customized to accommodate
existing object-oriented paradigms and to define new ones.

\beginSection{Objects and Classes}

Under this proposal, the primitive entities of Common Lisp are called
{\bit objects}.  Every Common Lisp data structure is an object that
is an {\bit instance\/} of a unique class.

A {\bit class\/} determines the structure and behavior of a set of
objects, called its {\bit instances}.  The class of an object
indirectly determines the set of operations into which the object can
enter.  It is an important feature of the \OS\ that all Lisp data
structures have a determinable class.

A class is itself an object.
Like other objects, all classes are themselves instances of other classes.
The class of the class of an object is termed the {\bit metaclass\/} of that
object.  Less formally, we will also use the term {\bit metaclass\/} to
refer to a class that has instances that are themselves classes.
The metaclass determines the form of inheritance used by its classes and
the representation of the instances of those classes.

A class can inherit properties directly or indirectly from one or more
other classes.  A class that is defined so as to inherit from another
class is said to {\bit include\/} that class.  A class that inherits
from a class is said to be a {\bit subclass\/} of that inherited
class.  A class from which another class inherits properties is called
a {\bit superclass\/} of the inheriting class.  The inheritance
relationship is transitive.

Classes are organized into a {\bit lattice}.  There is a mapping from
the Common Lisp type lattice into the Common Lisp Object System class
lattice.  All of the standard Common Lisp types specified in 
{\it Common Lisp: The Language\/} by Guy L. Steele Jr. except {\bf atom}
and {\bf common} have a corresponding class.

The \OS\ includes a set of standard objects.  We use the term 
{\bit standard object\/} to refer to any object whose metaclass is
{\bf class}.  The class {\bf object} specifies the default behavior of the
set of all objects whose metaclass is {\bf class}.  In other words,
all standard objects inherit (directly or indirectly) from the class
{\bf object}.

The \OS\ also defines a set of standard classes.  A {\bit standard
class\/} is any class that is an instance of the class {\bf class}.
The class {\bf class} is itself of class {\bf class}.  It is therefore
both a standard class and a standard object.  The class {\bf object}
is also a standard class since it is also an instance of the class
{\bf class}.  As a standard object, the class {\bf class} is a
subclass of the class {\bf object}.

\Vskip 1pc!
{\bf\tabskip 0pt plus 1fil
\halign to \hsize{&#\hfil\cr
\caption{Standard Common Lisp types.  All these types except atom and common have\break
a corresponding class.}

\beginsubSection{Defining Classes}

Classes with metaclass {\bf class} (standard classes)
are defined with the macro {\bf defclass}.
The use and definition of classes with other metaclasses %are
will be
discussed in the chapter ``Meta-Object Protocol.''

The syntax for {\bf defclass} is given in Figure~1-3.

The new class created by {\bf defclass} is a subclass of all the
classes specified in the {\it includes\/} list of the {\bf defclass}
form.  A class that is defined in this way is the most specific
element of a sublattice from which descriptions are inherited.  The
order of the classes in the {\it includes\/} list determines a local
precedence for classes and for the selection of methods.  The
transitive closure of all the {\it includes\/} specifies all the
classes that this class inherits from.  An ordering of this list for
purposes of precedence is called the {\bit class precedence list}.

The class precedence list for a standard class is computed as follows:

[To be spec'd.]
%1. A list is created, starting with the given class, of all the classes
%encountered in a depth-first traversal of
%the classes in the {\it includes\/} list of that class.  The classes in
%the {\it includes\/} list are processed in left-to-right order (the order
%of local precedence).
%2. If more than one occurrence of a class appears in the list that
%results from step 1, only the last occurrence of that class is kept.
%3. It is verified that the list that results from step 2 preserves the
%local precedence indicated in the {\it includes\/} list of each class
%encountered.  If any such local precedence is violated, an error is

\beginsubSection{Accessing Slots}

Slots can be accessed in two ways: by use of the accessors defined in
the {\bf defclass} form and by use of the primitive function
{\bf slot-value}.

The function {\bf slot-value} can be used with any of the slot names
specified in the {\bf defclass} form to access a specific slot in an object
of the given class.  If the object has no such slot, an error is

The automatically-generated accessors specified in the {\bf defclass} form
are implemented in terms of {\bf slot-value}.


\endSection%{Objects and Classes}

\beginSection{Generic Functions}

A {\bit generic function\/} is a function object, which, when it is invoked,
is able to designate one out of a set of operations, depending on the
classes of its arguments.  The generic function is said to
{\bit discriminate\/} on the classes of its arguments.

[The following is under discussion:
A generic function is a first-class object in the \CLOS.
It can be used as an argument to {\bf funcall} or {\bf apply} and
stored in the symbol-function cell of a symbol.]

[The following is under discussion:  A generic function is created
using the function {\bf make-generic} or the
macro {\bf defgeneric}. The macro {\bf defgeneric} stores the generic function
in a specified symbol-function cell.]

The operations that are provided by a generic function are defined by
the methods associated with it.

A {\bit method\/} is a function object.  It consists of two
parts: a set of argument
specifiers that is used to determine when it is applicable and a method
%Methods are first-class objects in the \CLOS.
A method can be used as an argument to {\bf funcall} or {\bf apply} and
stored in the symbol-function cell of a symbol.

A method can be defined and associated
with a generic function by using {\bf defmethod} or {\bf add-method}.
[An issue under discussion is whether a generic function must be defined
before any methods can be added to it.]

When a generic function is invoked, the arguments specifiers of its
associated methods are used to determine which method function is
An {\bit argument specifier} is the name of a class or an
The class of each of the arguments passed to the generic function
is determined and the classes of the arguments are then
compared with the
argument specifiers of each of the methods associated with the generic
function.  The method function of the method with the most specific
set of argument specifiers that are identical to or more general than
the classes of the arguments is invoked.  The order in which differences
between the classes of the arguments and the arguments specifiers are
considered is defined by the
{\bit argument precedence order\/} for the generic function. The relative
specificity of argument specifiers is determined by the class lattice.
%The {\bf class precedence list} is used to determine
%which specifier is more specific.
Any individual is always more specific than any class.  There
is a class named {\bf t} that is more general than any other class.  When every
argument specifier in the set of argument specifiers for a method is either
unspecified or {\bf t}, the method function for that method is called the
{\bit default method function\/} of the generic function.
%The precise definition for determining which method of a generic
%function to invoke will be given in section XXX.

\endSection%{Generic Functions}

\beginSection{Method Combination}

[To be written.]

We are currently working to integrate the programmatic ({\bf
run-super}) and declarative ({\bf define-method-combination}) method
combination techniques.  The references to method combination throughout
this document will be further specified in a future draft.

%Methods can be combined by means of the {\bf run-super} construct.
%The {\bf run-super} construct allows a method to specialize a ``super''

\endSection%{Method Combination}


The {\bit metaclass\/} of an object is the class of its class.  The metaclass
determines the form of inheritance used by its classes and
the representation of the instances of its classes.  The metaclass mechanism
can be used to provide particular forms of optimization or to tailor
the \OS\  for particular uses (such as the implementation of other
object languages---like Flavors, Smalltalk-80, and Loops).

Any new metaclass must define the structure of its instances, how their storage
is allocated, how their slots are accessed, and how slots and methods are
inherited.  The protocol for defining
metaclasses will be discussed in the chapter ``Meta-Object Protocol.''

\beginsubSection{Standard Metaclasses}

The \OS\  defines a number of {\bit standard metaclasses}.  These include
the following:
{\bf standard-type-class}, {\bf structure-class}, and {\bf class}.

The class {\bf standard-type-class} is a superclass of all the classes
that correspond to the standard Common Lisp types specified in
{\it Common Lisp: The Language\/} by Guy L. Steele Jr. except {\bf atom} and
{\bf common}.  These types are listed in Figure~1-1.
This metaclass allows the special kind of class
inheritance rules that are needed to handle the classes that 
correspond to the standard Common Lisp types.
It is not possible to make an instance
of a class whose class is {\bf standard-type-class} using the function
{\bf make-instance}.  
%It is possible to define methods for built-in classes.

The class {\bf structure-class} is a subclass of {\bf standard-type-class}.  
All classes defined by means of {\bf defstruct} are instances or
{\bf structure-class} or a subclass of {\bf structure-class}.
%The use of {\bf defstruct} implicitly defines a new class which is an
%instance of {\bf structure-class}.

%Instances of {\bf primitive-lisp-type-class} are classes that correspond
%to the basic Common Lisp types.  
%While all classes that correspond to the types
%listed in Figure~1-1 must be instances of either {\bf structure-class}
%or {\bf primitive-lisp-type-class}, no implementation is {\it required\/} to
%have any class that is an instance of {\bf primitive-lisp-type-class}.

\beginsubSection{Integrating Types and Classes}

The \OS\  maps the Common Lisp type space into the space
of classes.  
Figure~1-2 displays part of the lattice of classes that are instances of
a subclass of {\bf standard-type-class}.

Creating a type by means of {\bf defstruct} also creates a class in
this lattice.  Such a class is an instance of {\bf structure-class}
and an immediate subclass of the class that
corresponds to the type given as its
{\bf :includes} argument.  If no such type was specified, it
is an immediate subclass of the class {\bf t}.

The following precedence relations hold among classes:
{\bf list} has precedence over {\bf symbol} (for {\bf nil});
{\bf array} has precedence over {\bf sequence} (for vectors);
{\bf vector} has precedence over {\bf simple-array} (for simple-vectors);
{\bf bit-vector} has precedence over {\bf simple-array} (for simple-bit-vectors);
and {\bf string} has precedence over {\bf simple-array} (for simple-strings).

The classes {\bf number}, {\bf integer}, {\bf rational}, {\bf float},
{\bf list}, and {\bf sequence} are {\bit abstract classes}, that is,
they can never be directly instantiated.  The function {\bf class-of}
will never return one of these classes.

\endsubSection%{Integrating Types and Classes}

\beginsubSection{Lattice of classes that are instances of standard-type-class}
\def\IgnoreLineBreaks{\catcode'15=9     \catcode'12=9}
\def\IgnoreWhiteSpace{\catcode'11=9 \catcode'40=9 \IgnoreLineBreaks}

\font \pipefont= circlew10
\font \foofont = cmr10 at 1sp


\let \adv=\advance

\newdimen \stroke       
\stroke= \fontdimen8\pipefont   % thickness of line in circles
\newdimen \radius       \radius=6pt     % radius of circles

\newdimen\irad \irad=\radius\advance\irad by -.5\stroke
\newdimen\orad \orad=\radius\advance\irad by  .5\stroke



% Arrows

\advance\ArrowShift by -0.5\stroke

\def\StrikeOut #1
{       \setbox0\hbox{#1}
        \hbox to 1\wd0
        {       \vrule \he\stroke\de0pt\wi\wd0

{       \hskip 0.5\stroke
        \StrikeOut{\lower\ArrowShift\hbox to 10pt{\tensy\char'40\hss}}

{       \StrikeOut{\lower\ArrowShift\hbox to 10pt{\hss\tensy\char'41}}
        \hskip 0.5\stroke

{       \StrikeOut{\hskip 10pt\hskip 0.5\stroke}

{       \let\RightSideArrow=\ArrowLine

{       \let\LeftSideArrow=\ArrowLine

{       \let\LeftSideArrow=\ArrowLine
% boxes around tokens



\def\HorzLine{\hrule \he \stroke \de 0pt}

{\setbox1\vbox to 0pt{

{       \hbox{

{       \hbox{


% piping


\def\FulVert{\vrule             \wi\stroke\foo\hskip-\stroke}
\def\TopVert{\vrule\de-\irad    \wi\stroke\foo\hskip-\stroke}
\def\BotVert{\vrule\he-\orad    \wi\stroke\foo\hskip-\stroke}


\def\ru{\char'10\hskip -2\radius}
\def\rd{\char'11\hskip -2\radius}
\def\ld{\char'12\hskip -2\radius}
\def\lu{\char'13\hskip -2\radius}




%  ShiftBox


\vbox{  \everycr{\noalign{{\modifyrulebox\global\setbox\z\hbox{}}}}
        \global \setbox\z\hbox{\unhbox\z\vrule\he\ht\x\de\dp\x\wi0pt}

\global \setbox\y\vbox{}
\global \setbox\z\hbox{}

\global \setbox\y\box\tempy
\global \setbox\z\box\tempz



\global \let\modifyrulebox\topmod


}\caption{This figure shows all required subclass relationships among the classes that\break
are instances of
standard-type-class, with the exception of classes defined by means of\break
defstruct.  Implementations may choose to impose additional ones.}


%Includes objects for classes, objects for methods, objects for generic functions.

%Use: efficiency in implementation; experimentation.

%Allows for variations in the representation of objects, the syntax of
%methods, the combination of methods.

%Can be used to provide tuning and optimization for a particular application.