Expand unnecessary abbreviations
[clqr.git] / clqr-clos.tex
blobe73f07fea83814ba18731dac3d50f6d3be3b99c2
1 % Copyright (C) 2008, 2009, 2010, 2011, 2012 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{(\FU*{SLOT-EXISTS-P} \VAR{foo} \VAR{bar})\qquad\qquad}
22 \retval{\T} if \VAR{foo} has a slot \VAR{bar}.
25 \IT{(\FU*{SLOT-BOUNDP} \VAR{instance} \VAR{slot})}
27 \retval{\T} if \VAR{slot} in \VAR{instance} is bound.
30 \IT{(\MC*{DEFCLASS} \VAR{foo} (\OPn{\VAR{superclass}}\DF{\kwd{standard-object}})
31 (\xorGOO{\VAR{slot}\\
32 (\VAR{slot }
33 \orGOO{\Goos{\kwd{:reader} \VAR{reader}}\\
34 \Goos{\kwd{:writer} \xorGOO{\VAR{writer}\\
35 ({\kwd{setf}\VAR{ writer}})}{\}}} \\
36 \Goos{\kwd{:accessor} \VAR{accessor}} \\
37 \kwd{:allocation } \xorGOO{\kwd{:instance}\\
38 \kwd{:class}}{\}}\DF{\kwd{:instance}}\\
39 \Goos{\kwd{:initarg} \kwd{:}\VAR{initarg-name}} \\
40 \kwd{:initform} \VAR{ form}\\
41 \kwd{:type} \VAR{ type}\\
42 \kwd{:documentation} \VAR{ slot-doc}}{\}})}{\}^{\!\!\!*}})
43 \orGOO{(\kwd{:default-initargs } \Goos{\VAR{name}\VAR{ value}})\\
44 (\kwd{:documentation} \VAR{ class-doc})\\
45 (\kwd{:metaclass} \VAR{ name}\DF{\kwd{standard-class}})}{\}})}
47 Define, as a subclass of \VAR{superclass}es,
48 \retval{class \VAR{foo}}.
49 In a new instance \VAR{i}, a \VAR{slot}'s value defaults to
50 \VAR{form} unless set via \kwd{:}\VAR{initarg-name}; it is readable
51 via (\VAR{reader} \VAR{i}) or (\VAR{accessor} \VAR{i}), and
52 writeable via (\VAR{writer} \VAR{value} \VAR{i}) or (\kwd{setf}
53 (\VAR{accessor} \VAR{i}) \VAR{value}). With
54 \kwd{:allocation :class}, \VAR{slot} is shared by all instances of
55 class \VAR{foo}.
58 \IT{(\FU*{FIND-CLASS} \VAR{symbol} \OP{\VAR{errorp}\DF{\T}
59 \Op{\VAR{environment}}})}
61 Return \retval{class} named \VAR{symbol}. \kwd{setf}able.
64 \IT{(\GFU*{MAKE-INSTANCE} \VAR{class} \Goos{\kwd{:}\VAR{initarg}
65 \VAR{value}} \OPn{\VAR{other-keyarg}})}
67 Make new \retval{instance of \VAR{class}}.
70 \IT{(\GFU*{REINITIALIZE-INSTANCE} \VAR{instance} \Goos{\kwd{:}\VAR{initarg}
71 \VAR{value}} \OPn{\VAR{other-keyarg}})}
73 Change local slots of \retval{\VAR{instance}} according to
74 \VAR{initarg}s.
77 \IT{(\FU*{SLOT-VALUE} \VAR{foo} \VAR{slot})}
79 Return \retval{value
80 of \VAR{slot} in \VAR{foo}}. \kwd{SETF}able.
83 \IT{(\FU*{SLOT-MAKUNBOUND} \VAR{instance} \VAR{slot})}
85 Make \VAR{slot} in \retval{\VAR{instance}} unbound.
88 \IT{(\xorGOO{%
89 \MC*{WITH-SLOTS } (\Goos{\NEV{\VAR{slot}}\XOR(\NEV{\VAR{var}} \NEV{\VAR{slot}})})\\
90 \MC*{WITH-ACCESSORS } (\OPn{(\NEV{\VAR{var}}\text{ } \NEV{\VAR{accessor}})})}{\}}
91 \VAR{instance} \OPn{(\kwd{declare} \OPn{\NEV{\VAR{decl}}})}
92 \PROGN{\VAR{form}})}
94 Return \retval{values of \VAR{form}s} after evaluating them in a
95 lexical environment with slots of \VAR{instance} visible as
96 \kwd{setf}able \VAR{slot}s or \VAR{var}s/with \VAR{accessor}s of
97 \VAR{instance} visible as \kwd{setf}able \VAR{var}s.
100 \IT{\arrGOO{(\GFU*{CLASS-NAME } \VAR{class})\\
101 ((\kwd{setf } \GFU*{CLASS-NAME}) \VAR{ new-name } \VAR{class})}{.}}
103 Get/set \retval{name of \VAR{class}}.
106 \IT{(\FU*{CLASS-OF} \VAR{foo})}
108 \retval{Class} \VAR{foo} is a direct instance of.
111 \IT{(\GFU*{CHANGE-CLASS} \DES{\VAR{instance}} \VAR{new-class}
112 \Goos{\kwd{:}\VAR{initarg} \VAR{value}} \OPn{\VAR{other-keyarg}})}
114 Change class of \retval{\VAR{instance}} to \VAR{new-class}.
117 \IT{(\GFU*{MAKE-INSTANCES-OBSOLETE} \VAR{class})}
119 Update instances of \VAR{class}.
122 \IT{(\xorGOO{\GFU*{INITIALIZE-INSTANCE } (\VAR{instance})\\
123 \GFU*{UPDATE-INSTANCE-FOR-DIFFERENT-CLASS} \VAR{
124 previous }\VAR{current}}{\}}
125 \Goos{\kwd{:}\VAR{initarg}
126 \VAR{value}} \OPn{\VAR{other-keyarg}})}
128 Its primary method sets slots on behalf of \GFU{make-instance}/of
129 \GFU{change-class} by means of \GFU{shared-initialize}.
132 \IT{(\GFU*{UPDATE-INSTANCE-FOR-REDEFINED-CLASS} \VAR{instances}
133 \VAR{added-slots} \VAR{discarded-slots} \VAR{property-list}
134 \Goos{\kwd{:}\VAR{initarg}
135 \VAR{value}} \OPn{\VAR{other-keyarg}})}
137 Its primary method sets slots on behalf of
138 \GFU{make-instances-obsolete} by means of \GFU{shared-initialize}.
141 \IT{(\GFU*{ALLOCATE-INSTANCE} \VAR{class} \Goos{\kwd{:}\VAR{initarg}
142 \VAR{value}} \OPn{\VAR{other-keyarg}})}
144 Return uninitialized \retval{instance} of \VAR{class}. Called by
145 \GFU{make-instance}.
148 \IT{(\GFU*{SHARED-INITIALIZE} \VAR{instance}
149 \xorGOO{\VAR{slots}\\
150 \T}{\}}
151 \Goos{\kwd{:}\VAR{initarg}
152 \VAR{value}} \OPn{\VAR{other-keyarg}})}
154 Fill \VAR{instance}'s \VAR{slots} using \VAR{initarg}s and
155 \kwd{:initform} forms.
158 \IT{(\GFU*{SLOT-MISSING} \VAR{class} \VAR{object} \VAR{slot}
159 \xorGOO{\kwd{setf}\\
160 \kwd{slot-boundp}\\
161 \kwd{slot-makunbound}\\
162 \kwd{slot-value}}{\}}
163 \Op{\VAR{value}})}
165 Called in case of attempted access to missing \VAR{slot}. Its primary
166 method signals \kwd{error}.
169 \IT{(\GFU*{SLOT-UNBOUND} \VAR{class} \VAR{instance} \VAR{slot})}
171 Called by \FU{slot-value} in case of unbound \VAR{slot}. Its primary
172 method signals \kwd{unbound-slot}.
175 \end{LIST}
178 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
179 \subsection[Generic~Functns]{Generic Functions}
180 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182 \begin{LIST}{1cm}
183 \IT{(\FU*{NEXT-METHOD-P})}
185 \retval{\T} if enclosing method has a next method.
188 \IT{(\MC*{DEFGENERIC}
189 \xorGOO{\VAR{foo}\\ (\kwd{setf} \VAR{ foo})}{\}}
190 (\OPn{\VAR{required-var}}
191 \OP{\kwd{\&optional} \xorGOO{\VAR{var}\\
192 (\VAR{var})}{\}^{\!\!*}}}
193 \OP{\kwd{\&rest} \VAR{var}}
194 \OP{\kwd{\&key} \xorGOO{%
195 \VAR{var}\\
196 (\VAR{var}\XOR(\kwd{:}\VAR{key }
197 \VAR{var}))}{\}^{\!\!*}} \Op{\kwd{\&allow-other-keys}}})
198 \orGOO{%
199 (\kwd{:argument-precedence-order}\RP{\VAR{ required-var}})\\
200 (\kwd{declare }\RP{(\kwd{optimize}\OPn{\VAR{ arg}})})\\
201 (\kwd{:documentation } \NEV{\VAR{string}})\\
202 (\kwd{:generic-function-class} \VAR{ class}\DF{\kwd{standard-generic-function}})\\
203 (\kwd{:method-class} \VAR{ class}\DF{\kwd{standard-method}})\\
204 (\kwd{:method-combination} \VAR{ c-type}\DF{\kwd{standard}} \OPn{\VAR{ c-arg}})\\
205 \OPn{(\kwd{:method} \VAR{ defmethod-args})}}{\}})}
207 Define \retval{generic function} \VAR{foo}. \VAR{defmethod-args}
208 resemble those of \MC{defmethod}. For \VAR{c-type} see section
209 \ref{section:Method Combination Types}.
212 \IT{(\FU*{ENSURE-GENERIC-FUNCTION}
213 \xorGOO{\VAR{foo}\\ (\kwd{setf} \VAR{ foo})}{\}}
214 \orGOO{%
215 \kwd{:argument-precedence-order}\RP{\VAR{ required-var}}\\
216 \kwd{:declare }\RP{(\kwd{optimize}\OPn{\VAR{ arg}})}\\
217 \kwd{:documentation} \VAR{ string}\\
218 \kwd{:generic-function-class} \VAR{ class}\\
219 \kwd{:method-class} \VAR{ class}\\
220 \kwd{:method-combination} \VAR{ c-type} \OPn{\VAR{ c-arg}}\\
221 \kwd{:lambda-list} \VAR{ lambda-list}\\
222 \kwd{:environment} \VAR{ environment}}{\}})}
224 Define or modify \retval{generic function}
225 \VAR{foo}. \kwd{:generic-function-class} and \kwd{:lambda-list} have
226 to be compatible with a pre-existing generic function or with
227 existing methods, respectively. Changes to \kwd{:method-class} do
228 not propagate to existing methods. For \VAR{c-type} see section
229 \ref{section:Method Combination Types}.
232 \IT{(\MC*{DEFMETHOD}
233 \xorGOO{\VAR{foo}\\
234 (\kwd{setf} \VAR{ foo})}{\}}
235 \Op{\xorGOO{\kwd{:before}\\
236 \kwd{:after}\\
237 \kwd{:around}\\
238 \OPn{\VAR{qualifier}}}{\}}\DF{primary method}}
239 (\xorGOO{\VAR{var}\\
240 (\VAR{spec-var } \xorGOO{\VAR{class}\\
241 (\kwd{eql} \VAR{ bar})}{\}})}{\}^{\!\!*}}
242 \OP{\kwd{\&optional} \xorGOO{\VAR{var}\\
243 (\VAR{var } \OP{\VAR{init }
244 \Op{\VAR{supplied-p}}})}{\}^{\!\!*}}}
245 \Op{\kwd{\&rest} \VAR{var}}
246 \OP{\kwd{\&key} \xorGOO{\VAR{var}\\
247 (\xorGOO{\VAR{var}\\
248 (\kwd{:}\VAR{key }
249 \VAR{var})}{\}}
250 \OP{\VAR{init }\Op{\VAR{supplied-p}}})}{\}^{\!\!*}}
251 \Op{\kwd{\&allow-other-keys}}}
252 \OP{\kwd{\&aux }\xorGOO{\VAR{var}\\
253 (\VAR{var } \Op{\VAR{init}})}{\}^{\!\!*}}})
254 \orGOO{\OPn{(\kwd{declare } \OPn{\NEV{\VAR{decl}}})}\\
255 \NEV{\VAR{doc}}}{\}}
256 \PROGN{\VAR{form}})}
258 Define \retval{new method} for generic function
259 \VAR{foo}. \VAR{spec-var}s specialize to either being of \VAR{class}
260 or being \kwd{eql} \VAR{bar}, respectively. On invocation, \VAR{var}s and
261 \VAR{spec-var}s of the \retval{new method}
262 act like parameters of a function with body
263 \OPn{\VAR{form}}. \VAR{form}s are enclosed in an implicit \SO{block}
264 \VAR{foo}. Applicable \VAR{qualifier}s depend on the
265 \kwd{method-combination} type; see
266 section \ref{section:Method Combination Types}.
269 \IT{(\xorGOO{\GFU*{ADD-METHOD}\\
270 \GFU*{REMOVE-METHOD}}{\}} \VAR{generic-function} \VAR{method})}
272 Add (if necessary) or remove (if any) \VAR{method} to/from
273 \retval{\VAR{generic-function}}.
276 \IT{(\GFU*{FIND-METHOD} \VAR{generic-function} \VAR{qualifiers}
277 \VAR{specializers} \Op{\VAR{error}\DF{\T}})}
279 Return suitable \retval{method}, or signal \kwd{error}.
282 \IT{(\GFU*{COMPUTE-APPLICABLE-METHODS} \VAR{generic-function}
283 \VAR{args})}
285 \retval{List of methods} suitable for \VAR{args}, most specific first.
288 \IT{(\FU*{CALL-NEXT-METHOD} \OPn{\VAR{arg}}\DF{current args})}
290 From within a method, call next method with \VAR{arg}s; return
291 \retval{its values}.
294 \IT{(\GFU*{NO-APPLICABLE-METHOD} \VAR{generic-function}
295 \OPn{\VAR{arg}})}
297 Called on invocation of \VAR{generic-function} on \VAR{arg}s if
298 there is no applicable method. Default method signals \kwd{error}.
301 \IT{(\xorGOO{\FU*{INVALID-METHOD-ERROR} \VAR{ method}\\
302 \FU*{METHOD-COMBINATION-ERROR}}{\}}
303 \VAR{control} \OPn{\VAR{arg}})}
305 Signal \kwd{error} on applicable method with invalid qualifiers, or
306 on method combination. For \VAR{control} and \VAR{arg}s see
307 \kwd{format}, page \pageref{section:Format}.
310 \IT{(\GFU*{NO-NEXT-METHOD} \VAR{generic-function}
311 \VAR{method} \OPn{\VAR{arg}})}
313 Called on invocation of \kwd{call-next-method} when there is no next
314 method. Default method signals \kwd{error}.
317 \IT{(\GFU*{FUNCTION-KEYWORDS} \VAR{method})}
319 Return list of \retval{keyword parameters} of \VAR{method} and
320 \retvalii{\T} if other keys are allowed.
323 \IT{(\GFU*{METHOD-QUALIFIERS} \VAR{method})}
325 \retval{List of qualifiers} of \VAR{method}.
329 \end{LIST}
331 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
332 \subsection[Method Combi- nation Types]{Method Combination Types}
333 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
334 \label{section:Method Combination Types}
335 \begin{LIST}{1cm}
337 \IT{\kwd*{STANDARD}}
339 Evaluate most specific \kwd{:around} method supplying the values of
340 the generic function. From within this method, \FU{call-next-method}
341 can call less specific \kwd{:around} methods if there are any. If
342 not, or if there are no \kwd{:around} methods at all, call all
343 \kwd{:before} methods, most specific first, and the most specific
344 primary method which supplies the values of the calling
345 \FU{call-next-method} if any, or of the generic function; and which
346 can call less specific primary methods via
347 \FU{call-next-method}. After its return, call all \kwd{:after}
348 methods, least specific first.
351 \IT{\kwd*{AND}\XOR
352 \kwd*{OR}\XOR
353 \kwd*{APPEND}\XOR
354 \kwd*{LIST}\XOR \kwd*{NCONC}\XOR
355 \kwd*{PROGN}\XOR
356 \kwd*{MAX}\XOR
357 \kwd*{MIN}\XOR
358 \kwd*{+}}
360 Simple built-in \kwd{method-combination} types; have the same
361 usage as the
362 \VAR{c-type}s defined by the short form of
363 \MC{define-method-combination}.
366 \IT{(\MC*{DEFINE-METHOD-COMBINATION} \VAR{c-type}
367 \orGOO{%
368 \kwd{:documentation } \NEV{\VAR{string}}\\
369 \kwd{:identity-with-one-argument} \VAR{ bool}\DF{\NIL}\\
370 \kwd{:operator} \VAR{ operator}\DF{\VAR{c-type}}}{\}})}
372 \EM{Short Form. } Define new \kwd{method-combination}
373 \retval{\VAR{c-type}}. In a generic function using \VAR{c-type},
374 evaluate most specific \kwd{:around} method supplying the values of
375 the generic function. From within this method, \FU{call-next-method}
376 can call less specific \kwd{:around} methods if there are any. If
377 not, or if there are no \kwd{:around} methods at all,
378 return from the calling \kwd{call-next-method} or from the
379 generic function, respectively, the
380 values of (\VAR{operator} \OPn{(\VAR{primary-method}
381 \OPn{\VAR{gen-arg}})}), \OPn{\VAR{gen-arg}} being the arguments of the
382 generic function.
383 The \VAR{primary-method}s are ordered
384 \OP{\xorGOO{%
385 \kwd{:most-specific-first}\\
386 \kwd{:most-specific-last}%
387 }{\}}\DF{\kwd{:most-specific-first}}}
388 (specified as \VAR{c-arg} in \MC{defgeneric}).
389 Using \VAR{c-type} as the \VAR{qualifier} in \MC{defmethod}
390 makes the method primary.
393 \IT{(\MC*{DEFINE-METHOD-COMBINATION} \VAR{c-type}
394 (\OPn{\VAR{ord-$\lambda$}})
395 (\OPn{(\VAR{group} \xorGOO{%
396 \kwd{\A}\\
397 (\OPn{\VAR{qualifier}}\text{ } \OP{\kwd{\A}})\\
398 \VAR{predicate}}{\}}
399 \orGOO{%
400 \kwd{:description} \VAR{ control}\\
401 \kwd{:order }
402 \xorGOO{\kwd{:most-specific-first}\\
403 \kwd{:most-specific-last}}{\}}\DF{\kwd{:most-specific-first}}\\
404 \kwd{:required} \VAR{ bool}}{\}})})
405 \orGOO{%
406 (\kwd{:arguments } \OPn{\VAR{method-combination-$\lambda$}})\\
407 (\kwd{:generic-function} \VAR{ symbol})\\
408 \OPn{(\kwd{declare } \OPn{\NEV{\VAR{decl}}})}\\
409 \NEV{\VAR{doc}}}{\}}
410 \PROGN{\VAR{body}})}
412 \EM{Long Form. } Define new \kwd{method-combination}
413 \retval{\VAR{c-type}}. A call to a generic function using
414 \VAR{c-type} will be equivalent to a call to the forms returned by
415 \OPn{\VAR{body}} with \OPn{\VAR{ord-$\lambda$}} bound to
416 \OPn{\VAR{c-arg}} (cf.\ \MC{DEFGENERIC}), with \VAR{symbol} bound to
417 the generic function, with \OPn{\VAR{method-combination-$\lambda$}}
418 bound to the arguments of the generic function, and with
419 \VAR{group}s bound to lists of methods. An applicable method becomes
420 a member of the leftmost \VAR{group} whose \VAR{predicate} or
421 \VAR{qualifier}s match. Methods can be called via
422 \MC{CALL-METHOD}. Lambda lists (\OPn{\VAR{ord-$\lambda$}}) and
423 (\OPn{\VAR{method-combination-$\lambda$}}) according to
424 \VAR{ord-$\lambda$} on page \pageref{section:Functions}, the latter
425 enhanced by an optional \kwd{\&whole} argument.
428 \IT{(\MC*{CALL-METHOD} \xorGOO{\NEV{\VAR{method}}\\
429 (\MC*{MAKE-METHOD}\text{ } \NEV{\VAR{form}})}{\}}%
430 \OP{(\xorGOO{%
431 \NEV{\VAR{next-method}}\\
432 (\MC*{MAKE-METHOD}\text{ } \NEV{\VAR{form}})}{\}^{\!\!*}})})}
434 From within an effective method form, call \VAR{method} with the
435 arguments of the generic function and
436 with information about its \VAR{next-method}s; return \retval{its
437 values}.
440 \end{LIST}
444 %%% Local Variables:
445 %%% mode: latex
446 %%% TeX-master: "clqr"
447 %%% End: