\magnification=\magstephalf
\hyphenation{met-a-phor met-a-phors}
\baselineskip=12.78pt
\font\ninerm=cmr9
\font\nineit=cmti9
\font\ninett=cmtt9
% \font\bigfont=cmr10 at 14pt
\font\bigit=cmti10 at 14pt
\font\bigbf=cmb10 at 14pt
\font\bigtt=cmtt10 at 14pt
\hyphenchar\tentt=-1
\parskip=0pt plus12pt
\def\{{\char'173}
\def\}{\char'175}
\def\fig#1{\vbox{\vskip #1truein}\vskip 0pt plus1in}
\def\prgex{\smallskip\aftergroup\smallskip
\vskip 6pt
\baselineskip=12pt
% \ninett
\tt\obeyspaces %
\def\par{\leavevmode\endgraf} %
\obeylines\parindent=0pt\parskip=0pt}
\let \beginscheme=\prgex
\def\blockin{\advance\leftskip by 4pc
\advance\rightskip by 4pc\parindent=0pt}
\def\lessin{\advance\leftskip by 3pc
\advance\rightskip by 3pc\parindent=0pt}
\def\cite{\advance\leftskip by 1pc
\advance\rightskip by 1pc\parindent=0pt
\parindent=1em\ninerm\baselineskip=11pt}
\def\prechap#1{\centerline{\bigfont #1}}
\def\chapter#1{\centerline{\bigfont #1}\vskip 24pt}
\def\subhd#1{\goodbreak\vskip 12pt{\noindent\bf #1}\vskip 12pt}
\def\bkslsh{\char'134}
\def\vispc{\char'040}
\def\twiddle{\char'176}
% \hsize=29pc\vsize=40.166pc
{\obeyspaces\global\let =\ }
\def\mmake{\vskip 12pt
\baselineskip=11pt
\ninett\hangindent=3em\hangafter=1\raggedright}
\def\minit{\hyphenpenalty=10000\tolerance=1600}
\def\pmb#1{\setbox0=\hbox{#1}\noindent%
\kern-.025em\copy0\kern-\wd0%
\kern.05em\copy0\kern-\wd0%
\kern-.025em\raise.0433em\box0{}}
\def\idx#1{#1}%     index #1
\def\bkidx#1#2{#1 #2}%  index #1 #2 and #2, #1
\def\ttidx#1{{\tt #1}}% index {\tt #1}
\def\pasidx#1{#1}%  index "{\tt #1} (Pascal)"
\def\justidx#1{}%   index #1
\def\swapidx#1#2{#1 #2}%index #2, #1
\parindent=0pt
\parskip=6pt
\pageno=169

\subhd {Reference Manual for the OOP Language}

There are only three procedures that you need to use: {\tt define-class},
which defines a class; {\tt instantiate}, which takes a class as its
argument and returns an instance of the class; and {\tt ask}, which asks an
object to do something.  Here are the explanations of the procedures:

\bigskip

{\bigbf ASK:} {\bigtt (ask {\bigit object\/} {\bigit message\/} .\ {\bigit args\/})}


{\tt Ask} gets a method from {\it object\/} corresponding to {\it message}.
If the object has such a method, invoke it with the given {\it args\/};
otherwise it's an error.

\bigskip

{\bigbf INSTANTIATE:} {\bigtt (instantiate {\bigit class\/} .\ {\bigit arguments\/})}

{\tt Instantiate} creates a new instance of the given {\it class}, initializes
it, and returns it.  To initialize a class, {\tt instantiate} runs the
{\tt initialize} clauses of all the parent classes of the object
and then runs the {\tt initialize} clause of this class.

The extra arguments to {\tt instantiate} give the values of the new object's
instantiation variables.  So if you say

{\prgex%
(define-class (account balance) ...)
}

then saying

{\prgex%
(define my-acct (instantiate account 100))
}

will cause {\tt my-acct}'s {\tt balance} variable to be bound to 100.

\bigskip

{\bigbf DEFINE-CLASS:}

{\bigtt (define-class ({\bigit class-name\/} {\bigit args}...)\ {\bigit clauses}...)}

This defines a new class named {\it class-name}.  The instantiation
arguments for this class are {\it args}.  (See the explanation of {\tt
instantiate} above.)

The rest of the arguments to {\tt define-class} are various {\it clauses\/}
of the following types.  All clauses are optional.  You can have any number
of {\tt method} clauses, in any order.

{\advance\leftskip by 2pc
\advance\rightskip by 2pc

\pmb{{\tt (METHOD ({\it message\/} {\it arguments}...)\ {\it body\/})}}

A {\tt method} clause gives the class a method corresponding to the {\it
message}, with the given {\it arguments\/} and {\it body}.  A class
definition may contain any number of {\tt method} clauses.  You invoke
methods with {\tt ask}.  For example, say there's an object with a

{\prgex%
(method (add x y) (+ x y))
}

\noindent clause.  Then {\tt (ask object 'add 2 5)} returns 7.

Inside a method, the variable {\tt self} is bound to the object whose method
this is.  (Note that {\tt self} might be an instance of a child class of the
class in which the method is defined.)  A method defined within a particular
class has access to the instantiation variables, instance variables, and
class variables that are defined within the same class, but does {\it not\/}
have access to variables defined in parent or child classes.  (This is
similar to the scope rules for variables within procedures outside of the
OOP system.)

Any method that is usable within a given object can invoke any other such
method by invoking {\tt (ask self {\it message\/})}.  However, if a method
wants to invoke the method of the same name within a parent class, it must
instead ask for that explicitly by saying

{\prgex%
(usual {\it message\/} {\it args...\/})
}

\noindent where {\it message\/} is the name of the method you want and {\it
args...\/}\ are the arguments to the method.

\medskip

\pmb{{\tt (INSTANCE-VARS ({\it var1\/} {\it value1\/}) ({\it var2\/} {\it
value2\/}) ...)}
}

{\tt Instance-vars} sets up local state variables {\tt var1}, {\tt var2},
etc.  Each instance of the class will have its own private set of
variables with these names.
These are visible inside the bodies of the methods and the
initialization code within the same class definition.  The initial values of the
variables are calculated when an instance is created by evaluating the
expressions {\tt value1}, {\tt value2}, etc.  There can be any number of
variables.  Also, a method is automatically created for each variable that
returns its value.
If there is no {\tt instance-vars} clause then the instances
of this class won't
have any instance variables.  It is an error for a class definition to contain
more than one {\tt instance-vars} clause.

\medskip

\pmb{{\tt (CLASS-VARS ({\it var1\/} {\it value1\/}) ({\it var2\/} {\it
value2\/}) ...)}
}

{\tt Class-vars} sets up local state variables {\tt var1}, {\tt var2},
etc.  The class has only one set of variables with these names, shared
by every instance of the class.  (Compare the {\tt instance-vars}
clause described above.)
These variables are visible inside the bodies of the methods and the
initialization code within the same class definition.  The initial values of the
variables are calculated when the class is defined by evaluating the
expressions {\tt value1}, {\tt value2}, etc.  There can be any number of
variables.  Also, a method is automatically created for each variable that
returns its value.  If there is no {\tt class-vars} clause then the class won't
have any class variables.  It is an error for a class definition to contain
more than one {\tt class-vars} clause.

\medskip

\pmb{{\tt (PARENT ({\it parent1\/} {\it args}...)\ ({\it parent2\/} {\it args}...))}
}

{\tt Parent} defines the parents of a class.  The {\it args\/} are
the arguments used to instantiate the parent objects.  For example, let's
say that the {\tt rectangle} class has two arguments: {\tt height} and
{\tt width}:

{\prgex%
(define-class (rectangle height width) ...)
}

A {\tt square} is a kind of {\tt rectangle}; the {\tt height} and {\tt
width} of the {\tt square}'s {\tt rectangle} are both the {\tt side-length}
of the {\tt square}:

{\prgex%
(define-class (square side-length)
  (parent (rectangle side-length side-length))
  ...)
}

When an object class doesn't have an explicit method for a message it
receives, it looks for methods of that name (or default methods, as
explained below) in the definitions of the parent
classes, in the order they appear in the {\tt parent} clause.  The method
that gets invoked is from the first parent class that recognizes the message.

A method can invoke a parent's method of the same name with {\tt usual};
see the notes on the {\tt method} clause above.

\medskip

\pmb{{\tt (DEFAULT-METHOD {\it body\/})}}

A {\tt default-method} clause specifies the code that an object should
execute if it receives an unrecognized message (i.e., a message that does not
name a method in this class or any of its superclasses).  When the body is
executed, the variable {\tt message} is bound to the message, and the
variable {\tt args} is bound to a list of the additional arguments to {\tt
ask}.

\medskip

\pmb{{\tt (INITIALIZE {\it body\/})}}

The body of the {\tt initialize} clause contains code that is executed
whenever an instance of this class is created.

If the class has parents, their {\tt initialize} code gets executed before
the {\tt initialize} clause in the class itself.  If the class has two or more
parents, their {\tt initialize} code is executed in the order that they
appear in the {\tt parent} clause.

}

\bye
