continued work
[clqr.git] / clqr-clos.tex
blob34213bba640bdee576822e59ecb19d94cfebf49a
1 % Copyright (C) 2008 Bert Burgemeister
3 % Permission is granted to copy, distribute and/or modify this
4 % document under the terms of the GNU Free Documentation License,
5 % Version 1.2 or any later version published by the Free Software
6 % Foundation; with no Invariant Sections, no Front-Cover Texts and
7 % no Back-Cover Texts. For details see file COPYING.
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11 \section{CLOS}
12 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15 \subsection{Classes}
16 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18 \begin{LIST}{1cm}
20 \IT{(\GFU*{MAKE-INSTANCE} \VAR{class} \Goos{\kwd{:}\VAR{initarg}
21 \VAR{value}} \OPn{\VAR{other-keyarg}})}
23 Make new \retval{instance of \VAR{class}}.
26 \IT{(\GFU*{INITIALIZE-INSTANCE} (\VAR{instance}))}
28 Its primary method sets slots on behalf of
29 \GFU*{MAKE-INSTANCE}. Return \retval{instance}.
32 \IT{(\GFU*{REINITIALIZE-INSTANCE} \VAR{instance} \Goos{\kwd{:}\VAR{initarg}
33 \VAR{value}} \OPn{\VAR{other-keyarg}})}
35 Change local slots of \retval{\VAR{instance}} according to \VAR{initarg}s.
38 \IT{(\FU*{SLOT-VALUE} \VAR{instance} \VAR{slot})}
39 {Return \retval{value
40 of \VAR{slot} in \VAR{instance}}. \kwd{SETF}able.
43 \IT{(\SF*{WITH-SLOTS} (\Goos{\VAR{slot}\XOR(\VAR{var
44 slot})}) \VAR{instance} \OPn{(\kwd{declare} \OPn{\VAR{decl}})}
45 \OPn{\VAR{form}})}
47 Evaluate \VAR{form}s with slots of \VAR{instance} locally visible as
48 \VAR{slot}s or \VAR{var}s.
51 \IT{(\GFU*{CLASS-NAME} \VAR{class})}
53 \retval{Name of \VAR{class}}. \kwd{setf}able.
56 \IT{(\kwd*{CLASS-OF} \VAR{foo})}
58 \retval{Class} \VAR{foo} is an instance of.
61 \IT{(\FU*{FIND-CLASS} \VAR{symbol} \OP{\VAR{errorp}\DF{\T}
62 \Op{\VAR{environment}}})}
64 Return \retval{class object} named \VAR{symbol}. \kwd{setf}able.
67 \IT{(\SF*{DEFCLASS} \VAR{class-name} (\OPn{\VAR{superclass}})
68 (\GOOs{\VAR{slot}\XOR
69 (\VAR{slot}
70 \orGOO{\Goos{\kwd{:reader} \VAR{reader-fu}}\\
71 \Goos{\kwd{:writer} \VAR{writer-fu}} \\
72 \Goos{\kwd{:accessor} \VAR{reader-fu}} \\
73 \kwd{:allocation } \Goo{\kwd{:instance}\XOR\kwd{:class}}\\
74 \Goos{\kwd{:initarg} \kwd{:}\VAR{arg}} \\
75 \kwd{:initform} \VAR{ form}\\
76 \kwd{:type} \VAR{ type}\\
77 \kwd{:documentation} \VAR{ string}}{\}})})
78 \orGOO{(\kwd{:default-initargs} \Goos{\VAR{name}\VAR{ value}})\\
79 (\kwd{:documentation} \VAR{ string})\\
80 (\kwd{:metaclass} \VAR{ name})}{\}})}
82 Define \retval{class \VAR{ class-name}} as a subclass of \VAR{superclass}es.
85 \IT{(\GFU*{CHANGE-CLASS} \VAR{instance} \VAR{new-class} \Goos{\kwd{:}\VAR{initarg}
86 \VAR{value}} \OPn{\VAR{other-keyarg}})}
88 Change class of \retval{\VAR{instance}} to \VAR{new-class}.
91 \IT{(\GFU*{UPDATE-INSTANCE-FOR-DIFFERENT-CLASS} \VAR{previous}
92 \VAR{current} \Goos{\kwd{:}\VAR{initarg}
93 \VAR{value}} \OPn{\VAR{other-keyarg}})}
95 Called by \kwd{change-class}.
98 \IT{(\kwd*{MAKE-INSTANCES-OBSOLETE} \VAR{class})}
100 Update instances of \VAR{class}.
103 \IT{(\GFU*{UPDATE-INSTANCE-FOR-REDEFINED-CLASS} \VAR{instances}
104 \VAR{added-slots} \VAR{discarded-slots} \VAR{property-list}
105 \Goos{\kwd{:}\VAR{initarg}
106 \VAR{value}} \OPn{\VAR{other-keyarg}})}
108 Called by \kwd{make-instances-obsolete}.
111 \IT{(\GFU*{SHARED-INITIALIZE} \VAR{instance} \VAR{slots}
112 \Goos{\kwd{:}\VAR{initarg}
113 \VAR{value}} \OPn{\VAR{other-keyarg}})}
115 Fill \VAR{instance}'s \VAR{slots} using \VAR{init-args} and
116 \kwd{:initform} forms.
119 \IT{(\GFU*{SLOT-MISSING} \VAR{class} \VAR{object} \VAR{slot}
120 \xorGOO{\kwd{setf}\\
121 \kwd{slot-boundp}\\
122 \kwd{slot-makunbound}}{\}}
123 \Op{\VAR{value}})}
125 Called in case of attempted access to missing \VAR{slot}. Default primary
126 method signals \kwd{error}.
129 \IT{(\GFU*{SLOT-UNBOUND} \VAR{class} \VAR{instance} \VAR{slot})}
131 Called by \kwd{slot-value} in case of unbound \VAR{slot}. Default primary
132 method signals \kwd{unbound-slot}.
135 \end{LIST}
138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139 \subsection{Generic Functions}
140 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
142 \begin{LIST}{1cm}
143 \IT{(\FU*{NEXT-METHOD-P})}
145 \retval{\T} if enclosing method has a next method.
148 \IT{(\SF*{DEFGENERIC}
149 \xorGOO{\VAR{name}\\ (\kwd{setf} \VAR{ name})}{\}}
150 (\OPn{\VAR{var}}%
151 \OP{\kwd*{\&optional} \Goos{\VAR{var}\XOR(\VAR{var})}}
152 \OP{\kwd*{\&rest} \VAR{var}}
153 \OP{\kwd*{\&key} \orGOO{%
154 \VAR{var}\\
155 (\VAR{var}\XOR(\kwd{:}\VAR{key}
156 \VAR{var}))}{\}^{\!\!*}} \Op{\kwd*{\&allow-other-keys}}})
157 \orGOO{%
158 (\kwd{:argument-precendence-order}\RP{\VAR{ var}})\\
159 (\kwd{declare }\RP{(\kwd{optimize}\OPn{\VAR{ arg}})})\\
160 (\kwd{:documentation} \VAR{ string})\\
161 (\kwd{:generic-function-class} \VAR{ class}\DF{\kwd{standard-generic-function}})\\
162 (\kwd{:method-class} \VAR{ class}\DF{\kwd{standard-method}})\\
163 (\kwd{:method-combination} \VAR{ c-type} \OPn{\VAR{ arg}})\\
164 \OPn{(\kwd{:method} \VAR{ defmethod-arguments})}}{\}})}
166 Define \retval{generic function \VAR{name}}. For \VAR{c-type} see
167 s.\ \ref{section:Method Combination Types}.
170 \IT{(\FU*{ENSURE-GENERIC-FUNCTION}
171 \xorGOO{\VAR{name}\\ (\kwd{setf} \VAR{ name})}{\}}
172 \orGOO{%
173 \kwd{:argument-precendence-order}\RP{\VAR{ arg}}\\
174 \kwd{:declare }\RP{(\kwd{optimize}\OPn{\VAR{ arg}})}\\
175 \kwd{:documentation} \VAR{ string}\\
176 \kwd{:environment} \VAR{ environment}\\
177 \kwd{:generic-function-class} \VAR{ class}\\
178 \kwd{:lambda-list} \VAR{ lambda-list}\\
179 \kwd{:method-class} \VAR{ class}\\
180 \kwd{:method-combination} \VAR{ c-type} \OPn{\VAR{ arg}}}{\}})}
182 Define or modify \retval{generic function \VAR{name}}. For \VAR{c-type} see
183 s.\ \ref{section:Method Combination Types}.
186 \IT{(\SF*{DEFMETHOD}
187 \xorGOO{\VAR{bar}\\ (\kwd{setf} \VAR{ bar})}{\}}
188 \Op{\xorGOO{\kwd{:before}\\
189 \kwd{:after}\\
190 \kwd{:around}}{\}}}
191 (\xorGOO{\VAR{var}\\
192 (\VAR{spec-var } \xorGOO{\VAR{class}\\(\kwd{eql} \VAR{ foo})}{\}})}{\}^{\!\!*}}
193 \OP{\kwd*{\&optional} \Goos{\VAR{var}\XOR(\VAR{var} \OP{\VAR{init}
194 \Op{\VAR{supplied-p}}})}}
195 \Op{\kwd*{\&rest} \VAR{var}}
196 \OP{\kwd*{\&key} \GOos{\VAR{var}\XOR(\Goo{\VAR{var}\XOR(\kwd{:}\VAR{key}
197 \VAR{var})}
198 \OP{\VAR{init }\Op{\VAR{supplied-p}}})}
199 \Op{\kwd*{\&allow-other-keys}}}
200 \OP{\kwd*{\&aux }\Goos{\VAR{var}\XOR(\VAR{var} \Op{\VAR{init}})}})
201 \orGOO{\OPn{(\kwd{declare} \OPn{\VAR{ decl}})}\\
202 \VAR{documentation}}{\}}
203 \OPn{\VAR{form}})}
205 Define \retval{new method} for generic function
206 \VAR{bar}. \VAR{spec-var}s specialize to either being of \VAR{class}
207 or being \kwd{eql} \VAR{foo}, respectively. On invocation, \VAR{var}s and
208 \VAR{spec-var}s of the \retval{new method}
209 act like parameters of a function with body \VAR{foo}.
212 \IT{(\xorGOO{\GFU*{ADD-METHOD}\\
213 \GFU*{REMOVE-METHOD}}{\}} \VAR{generic-function} \VAR{method})}
215 Add, or remove, respectively, \VAR{method} from \retval{\VAR{generic-function}}.
218 \IT{(\FU*{CALL-NEXT-METHOD} \OPn{\VAR{args}}\DF{current args})}
220 From within a method, call next method with \VAR{arg}s; return
221 \retval{its values}.
224 \IT{(\SF*{CALL-METHOD} \orGOO{\VAR{method}\\
225 (\SF*{MAKE-METHOD} \VAR{ form})}{\}}
226 \Op{\VAR{next-methods}})}
228 Call \VAR{method}, return \retval{its values}.
231 \IT{(\GFU*{NO-APPLICABLE-METHOD} \VAR{generic-function}
232 \OPn{\VAR{arg}})}
234 Called on invocation of \VAR{generic-function} if there is no applicable method.
237 \IT{(\xorGOO{\FU*{INVALID-METHOD-ERROR} \VAR{ method}\\
238 \FU*{METHOD-COMBINATION-ERROR}}{\}}
239 \VAR{control} \OPn{\VAR{arg}})}
241 Signal \kwd{error} on applicable method, or on method combination,
242 with invalid qualifiers. For \VAR{control} and \VAR{arg}s see
243 \kwd{format}, p.\ \pageref{section:Format}.
246 \IT{(\GFU*{NO-NEXT-METHOD} \VAR{generic-function}
247 \VAR{method} \OPn{\VAR{arg}})}
249 Called on invocation of \kwd{call-next-method} if there is no next method.
252 \IT{(\GFU*{FUNCTION-KEYWORDS} \VAR{method})}
254 Return list of \retval{keyword parameters} of \VAR{method} and
255 \retvalii{\T} of other keys are alowed.
258 \IT{(\GFU*{ALLOCATE-INSTANCE} \VAR{class} \Goos{\kwd{:}\VAR{initarg}
259 \VAR{value}} \OPn{\VAR{other-keyarg}})}
261 Return uninitialized \retval{instance} of \VAR{class}.
264 \IT{(\GFU*{METHOD-QUALIFIERS} \VAR{method})}
266 List of qualifiers of \VAR{method}.
269 \IT{(\GFU*{FIND-METHOD} \VAR{generic-function} \VAR{qualifiers}
270 \VAR{specializers} \Op{\VAR{error}\DF{\T}})}
272 Return suitable \retval{method}, or signal \kwd{error}.
275 \IT{(\GFU*{COMPUTE-APPLICABLE-METHODS} \VAR{generic-function}
276 \VAR{args})}
278 \retval{List of methods} suitable for \VAR{args}, most specific first.
282 \end{LIST}
284 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
285 \subsection{Method Combination Types}
286 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
287 \label{section:Method Combination Types}
288 \begin{LIST}{1cm}
290 \IT{\arrGOO{\kwd*{AND}\\
291 \kwd*{OR}\\
292 \kwd*{APPEND}\\
293 \kwd*{LIST}\\
294 \kwd*{NCONC}\\
295 \kwd*{PROGN}\\
296 \kwd*{MAX}\\
297 \kwd*{MIN}\\
298 \kwd*{+}}{.}}
300 Built-in method combination types.
303 \IT{\kwd*{STANDARD}}
305 Standard method combination type, also used if no method combination
306 type is given.
309 \IT{(\SF*{DEFINE-METHOD-COMBINATION} \VAR{c-type} \orGOO{%
310 \kwd{:documentation} \VAR{ string}\\
311 \kwd{:identity-with-one-argument} \VAR{ bool}\DF{\NIL}\\
312 \kwd{:operator} \VAR{ operator}\DF{\VAR{c-type}}}{\}})}
314 Short form. Define new method combination type
315 \retval{\VAR{c-type}}. A call to a generic function using
316 \VAR{c-type} will be equivalent to (\VAR{c-type}
317 \OPn{\VAR{applicable-method}}).
320 \IT{(\SF*{DEFINE-METHOD-COMBINATION} \VAR{c-type}
321 (\OPn{\VAR{fu-arg}})
322 (\GOOs{\VAR{name} \xorGOO{%
323 \GOOp{\VAR{list}\XOR\kwd{*}}\\
324 \VAR{predicate}}{\}} \orGOO{%
325 \kwd{:description} \VAR{ control}\\
326 \kwd{:order }
327 \Goo{\kwd{:most-specific-first}\XOR\kwd{:most-specific-last}}\\
328 \kwd{:required} \VAR{ bool}}{\}}})
329 \Op{\kwd{:arguments} (\OPn{\VAR{method-combination-arg}})}
330 \Op{\kwd{:generic-function} \VAR{ symbol}}
331 \orGOO{\OPn{(\kwd{declare} \OPn{\VAR{ decl}})}\\
332 \VAR{documentation}}{\}}
333 \OPn{\VAR{body}})}
335 Long form. A call to a generic function using \VAR{c-type} will
336 equivalent to a call to the forms returned by \VAR{body}. Lambda
337 lists (\OPn{\VAR{fu-arg}}) and (\OPn{\VAR{method-combination-arg}})
338 according to \VAR{fu-arg} on p.\ \pageref{section:Functions}, the
339 latter enhanced by an optional \kwd{\&whole} argument.
342 \end{LIST}