changed defsetf entry
[clqr.git] / clqr-clos.tex
blob596d5deffd3b8bcee188e60af2939f802d6d340d
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{(\FU*{SLOT-BOUNDP} \VAR{instance} \VAR{slot})}
22 \retval{\T} if \VAR{slot} in \VAR{instance} is bound.
25 \IT{(\MC*{DEFCLASS} \VAR{class-name} (\OPn{\VAR{superclass}})
26 (\OPn{\xorGOO{\VAR{slot}\\
27 (\VAR{slot}
28 \orGOO{\Goos{\kwd{:reader} \VAR{reader-fu}}\\
29 \Goos{\kwd{:writer} \VAR{writer-fu}} \\
30 \Goos{\kwd{:accessor} \VAR{reader-fu}} \\
31 \kwd{:allocation } \Goo{\kwd{:instance}\XOR\kwd{:class}}\\
32 \Goos{\kwd{:initarg} \kwd{:}\VAR{arg}} \\
33 \kwd{:initform} \VAR{ form}\\
34 \kwd{:type} \VAR{ type}\\
35 \kwd{:documentation} \VAR{ string}}{\}})}{\}}})
36 \orGOO{(\kwd{:default-initargs} \Goos{\VAR{name}\VAR{ value}})\\
37 (\kwd{:documentation} \VAR{ string})\\
38 (\kwd{:metaclass} \VAR{ name})}{\}})}
40 Define \retval{class \VAR{ class-name}} as a subclass of
41 \VAR{superclass}es. %FIXME:AUGMENT
44 \IT{(\FU*{FIND-CLASS} \VAR{symbol} \OP{\VAR{errorp}\DF{\T}
45 \Op{\VAR{environment}}})}
47 Return \retval{class object} named \VAR{symbol}. \kwd{setf}able.
50 \IT{(\GFU*{MAKE-INSTANCE} \VAR{class} \Goos{\kwd{:}\VAR{initarg}
51 \VAR{value}} \OPn{\VAR{other-keyarg}})}
53 Make new \retval{instance of \VAR{class}}.
56 \IT{(\GFU*{INITIALIZE-INSTANCE} (\VAR{instance}))}
58 Its primary method sets slots on behalf of
59 \GFU*{MAKE-INSTANCE}. Return \retval{instance}.
62 \IT{(\GFU*{REINITIALIZE-INSTANCE} \VAR{instance} \Goos{\kwd{:}\VAR{initarg}
63 \VAR{value}} \OPn{\VAR{other-keyarg}})}
65 Change local slots of \retval{\VAR{instance}} according to \VAR{initarg}s.
68 \IT{(\FU*{SLOT-VALUE} \VAR{instance} \VAR{slot})}
69 {Return \retval{value
70 of \VAR{slot} in \VAR{instance}}. \kwd{SETF}able.
73 \IT{(\FU*{SLOT-MAKUNBOUND} \VAR{instance} \VAR{slot})}
75 Make \VAR{slot} in \retval{\VAR{instance}} unbound.
78 \IT{(\MC*{WITH-SLOTS} (\Goos{\VAR{slot}\XOR(\VAR{var
79 slot})}) \VAR{instance} \OPn{(\kwd{declare} \OPn{\NEV{\VAR{decl}}})}
80 \OPn{\VAR{form}})}
82 Evaluate \VAR{form}s with slots of \VAR{instance} locally visible as
83 \VAR{slot}s or \VAR{var}s.
86 \IT{(\MC*{WITH-ACCESSORS} (\OPn{(\NEV{\VAR{var}} \NEV{\VAR{accessor}})})
87 \VAR{instance} \OPn{(\kwd{declare} \OPn{\NEV{\VAR{decl}}})}
88 \OPn{\VAR{form}})}
90 Evaluate \VAR{form}s with variables \VAR{var} locally bound to
91 \VAR{accessor}s of \VAR{instance}.
92 Return \retval{values of \VAR{form}s}.
95 \IT{(\GFU*{CLASS-NAME} \VAR{class})}
97 \retval{Name of \VAR{class}}. \kwd{setf}able.
100 \IT{(\FU*{CLASS-OF} \VAR{foo})}
102 \retval{Class} \VAR{foo} is an instance of.
105 \IT{(\GFU*{CHANGE-CLASS} \DES{\VAR{instance}} \VAR{new-class}
106 \Goos{\kwd{:}\VAR{initarg} \VAR{value}} \OPn{\VAR{other-keyarg}})}
108 Change class of \retval{\VAR{instance}} to \VAR{new-class}.
111 \IT{(\GFU*{UPDATE-INSTANCE-FOR-DIFFERENT-CLASS} \VAR{previous}
112 \VAR{current} \Goos{\kwd{:}\VAR{initarg}
113 \VAR{value}} \OPn{\VAR{other-keyarg}})}
115 Called by \GFU{change-class}.
118 \IT{(\GFU*{MAKE-INSTANCES-OBSOLETE} \VAR{class})}
120 Update instances of \VAR{class}.
123 \IT{(\GFU*{UPDATE-INSTANCE-FOR-REDEFINED-CLASS} \VAR{instances}
124 \VAR{added-slots} \VAR{discarded-slots} \VAR{property-list}
125 \Goos{\kwd{:}\VAR{initarg}
126 \VAR{value}} \OPn{\VAR{other-keyarg}})}
128 Called by \GFU{make-instances-obsolete}.
131 \IT{(\GFU*{SHARED-INITIALIZE} \VAR{instance} \VAR{slots}
132 \Goos{\kwd{:}\VAR{initarg}
133 \VAR{value}} \OPn{\VAR{other-keyarg}})}
135 Fill \VAR{instance}'s \VAR{slots} using \VAR{initarg}s and
136 \kwd{:initform} forms.
139 \IT{(\GFU*{SLOT-MISSING} \VAR{class} \VAR{object} \VAR{slot}
140 \xorGOO{\kwd{setf}\\
141 \kwd{slot-boundp}\\
142 \kwd{slot-makunbound}}{\}}
143 \Op{\VAR{value}})}
145 Called in case of attempted access to missing \VAR{slot}. Default primary
146 method signals \kwd{error}.
149 \IT{(\GFU*{SLOT-UNBOUND} \VAR{class} \VAR{instance} \VAR{slot})}
151 Called by \FU{slot-value} in case of unbound \VAR{slot}. Default primary
152 method signals \kwd{unbound-slot}.
155 \end{LIST}
158 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
159 \subsection[Generic~Functns]{Generic Functions}
160 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
162 \begin{LIST}{1cm}
163 \IT{(\FU*{NEXT-METHOD-P})}
165 \retval{\T} if enclosing method has a next method.
168 \IT{(\MC*{DEFGENERIC}
169 \xorGOO{\VAR{name}\\ (\kwd{setf} \VAR{ name})}{\}}
170 (\OPn{\VAR{var}}%
171 \OP{\kwd*{\&optional} \Goos{\VAR{var}\XOR(\VAR{var})}}
172 \OP{\kwd*{\&rest} \VAR{var}}
173 \OP{\kwd*{\&key} \orGOO{%
174 \VAR{var}\\
175 (\VAR{var}\XOR(\kwd{:}\VAR{key}
176 \VAR{var}))}{\}^{\!\!*}} \Op{\kwd*{\&allow-other-keys}}})
177 \orGOO{%
178 (\kwd{:argument-precedence-order}\RP{\VAR{ var}})\\
179 (\kwd{declare }\RP{(\kwd{optimize}\OPn{\VAR{ arg}})})\\
180 (\kwd{:documentation } \NEV{\VAR{string}})\\
181 (\kwd{:generic-function-class} \VAR{ class}\DF{\kwd{standard-generic-function}})\\
182 (\kwd{:method-class} \VAR{ class}\DF{\kwd{standard-method}})\\
183 (\kwd{:method-combination} \VAR{ c-type} \OPn{\VAR{ arg}})\\
184 \OPn{(\kwd{:method} \VAR{ defmethod-arguments})}}{\}})}
186 Define \retval{generic function \VAR{name}}. For \VAR{c-type} see
187 s.\ \ref{section:Method Combination Types}. %FIXME:AUGMENT
190 \IT{(\FU*{ENSURE-GENERIC-FUNCTION}
191 \xorGOO{\VAR{name}\\ (\kwd{setf} \VAR{ name})}{\}}
192 \orGOO{%
193 \kwd{:argument-precedence-order}\RP{\VAR{ arg}}\\
194 \kwd{:declare }\RP{(\kwd{optimize}\OPn{\VAR{ arg}})}\\
195 \kwd{:documentation} \VAR{ string}\\
196 \kwd{:environment} \VAR{ environment}\\
197 \kwd{:generic-function-class} \VAR{ class}\\
198 \kwd{:lambda-list} \VAR{ lambda-list}\\
199 \kwd{:method-class} \VAR{ class}\\
200 \kwd{:method-combination} \VAR{ c-type} \OPn{\VAR{ arg}}}{\}})}
202 Define or modify \retval{generic function \VAR{name}}. For \VAR{c-type} see
203 s.\ \ref{section:Method Combination Types}. %FIXME:AUGMENT
206 \IT{(\MC*{DEFMETHOD}
207 \xorGOO{\VAR{bar}\\ (\kwd{setf} \VAR{ bar})}{\}}
208 \Op{\xorGOO{\kwd{:before}\\
209 \kwd{:after}\\
210 \kwd{:around}}{\}}}
211 (\xorGOO{\VAR{var}\\
212 (\VAR{spec-var } \xorGOO{\VAR{class}\\
213 (\kwd{eql} \VAR{ foo})}{\}})}{\}^{\!\!*}}
214 \OP{\kwd*{\&optional} \Goos{\VAR{var}\XOR(\VAR{var} \OP{\VAR{init}
215 \Op{\VAR{supplied-p}}})}}
216 \Op{\kwd*{\&rest} \VAR{var}}
217 \OP{\kwd*{\&key} \GOos{\VAR{var}\XOR(\Goo{\VAR{var}\XOR(\kwd{:}\VAR{key}
218 \VAR{var})}
219 \OP{\VAR{init }\Op{\VAR{supplied-p}}})}
220 \Op{\kwd*{\&allow-other-keys}}}
221 \OP{\kwd*{\&aux }\Goos{\VAR{var}\XOR(\VAR{var} \Op{\VAR{init}})}})
222 \orGOO{\OPn{(\kwd{declare } \OPn{\NEV{\VAR{decl}}})}\\
223 \NEV{\VAR{doc}}}{\}}
224 \OPn{\VAR{form}})}
226 Define \retval{new method} for generic function
227 \VAR{bar}. \VAR{spec-var}s specialize to either being of \VAR{class}
228 or being \kwd{eql} \VAR{foo}, respectively. On invocation, \VAR{var}s and
229 \VAR{spec-var}s of the \retval{new method}
230 act like parameters of a function with body \OPn{\VAR{form}}.
233 \IT{(\xorGOO{\GFU*{ADD-METHOD}\\
234 \GFU*{REMOVE-METHOD}}{\}} \VAR{generic-function} \VAR{method})}
236 Add, or remove, respectively, \VAR{method} from \retval{\VAR{generic-function}}.
239 \IT{(\FU*{CALL-NEXT-METHOD} \OPn{\VAR{args}}\DF{current args})}
241 From within a method, call next method with \VAR{arg}s; return
242 \retval{its values}.
245 \IT{(\MC*{CALL-METHOD} \orGOO{\NEV{\VAR{method}}\\
246 (\MC*{MAKE-METHOD} \VAR{ form})}{\}}
247 \Op{\NEV{\VAR{next-methods}}})}
249 Call \VAR{method}, return \retval{its values}. %FIXME:AUGMENT
252 \IT{(\GFU*{NO-APPLICABLE-METHOD} \VAR{generic-function}
253 \OPn{\VAR{arg}})}
255 Called on invocation of \VAR{generic-function} if there is no applicable method.
258 \IT{(\xorGOO{\FU*{INVALID-METHOD-ERROR} \VAR{ method}\\
259 \FU*{METHOD-COMBINATION-ERROR}}{\}}
260 \VAR{control} \OPn{\VAR{arg}})}
262 Signal \kwd{error} on applicable method, or on method combination,
263 with invalid qualifiers. For \VAR{control} and \VAR{arg}s see
264 \kwd{format}, p.\ \pageref{section:Format}.
267 \IT{(\GFU*{NO-NEXT-METHOD} \VAR{generic-function}
268 \VAR{method} \OPn{\VAR{arg}})}
270 Called on invocation of \kwd{call-next-method} if there is no next method.
273 \IT{(\GFU*{FUNCTION-KEYWORDS} \VAR{method})}
275 Return list of \retval{keyword parameters} of \VAR{method} and
276 \retvalii{\T} of other keys are allowed.
279 \IT{(\GFU*{ALLOCATE-INSTANCE} \VAR{class} \Goos{\kwd{:}\VAR{initarg}
280 \VAR{value}} \OPn{\VAR{other-keyarg}})}
282 Return uninitialized \retval{instance} of \VAR{class}.
285 \IT{(\GFU*{METHOD-QUALIFIERS} \VAR{method})}
287 List of qualifiers of \VAR{method}.
290 \IT{(\GFU*{FIND-METHOD} \VAR{generic-function} \VAR{qualifiers}
291 \VAR{specializers} \Op{\VAR{error}\DF{\T}})}
293 Return suitable \retval{method}, or signal \kwd{error}.
296 \IT{(\GFU*{COMPUTE-APPLICABLE-METHODS} \VAR{generic-function}
297 \VAR{args})}
299 \retval{List of methods} suitable for \VAR{args}, most specific first.
303 \end{LIST}
305 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
306 \subsection[Method Combi- nation Types]{Method Combination Types}
307 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
308 \label{section:Method Combination Types}
309 \begin{LIST}{1cm}
311 \IT{\arrGOO{\kwd*{AND}\\
312 \kwd*{OR}\\
313 \kwd*{APPEND}\\
314 \kwd*{LIST}\\
315 \kwd*{NCONC}\\
316 \kwd*{PROGN}\\
317 \kwd*{MAX}\\
318 \kwd*{MIN}\\
319 \kwd*{+}}{.}}
321 Built-in method combination types.
324 \IT{\kwd*{STANDARD}}
326 Standard method combination type, also used if no method combination
327 type is given.
330 \IT{(\MC*{DEFINE-METHOD-COMBINATION} \VAR{c-type} \orGOO{%
331 \kwd{:documentation } \NEV{\VAR{string}}\\
332 \kwd{:identity-with-one-argument} \VAR{ bool}\DF{\NIL}\\
333 \kwd{:operator} \VAR{ operator}\DF{\VAR{c-type}}}{\}})}
335 Short form. Define new method combination type
336 \retval{\VAR{c-type}}. A call to a generic function using
337 \VAR{c-type} will be equivalent to (\VAR{c-type}
338 \OPn{\VAR{applicable-method}}).
341 \IT{(\MC*{DEFINE-METHOD-COMBINATION} \VAR{c-type}
342 (\OPn{\VAR{ord-$\lambda$}})
343 (\GOOs{\VAR{name} \xorGOO{%
344 \GOOp{\VAR{list}\XOR\kwd{*}}\\
345 \VAR{predicate}}{\}} \orGOO{%
346 \kwd{:description} \VAR{ control}\\
347 \kwd{:order }
348 \Goo{\kwd{:most-specific-first}\XOR\kwd{:most-specific-last}}\\
349 \kwd{:required} \VAR{ bool}}{\}}})
350 \Op{\kwd{:arguments} (\OPn{\VAR{method-combination-arg}})}
351 \Op{\kwd{:generic-function} \VAR{ symbol}}
352 \orGOO{\OPn{(\kwd{declare } \OPn{\NEV{\VAR{decl}}})}\\
353 \NEV{\VAR{doc}}}{\}}
354 \OPn{\VAR{body}})}
356 Long form. A call to a generic function using \VAR{c-type} will be
357 equivalent to a call to the forms returned by \VAR{body}. Lambda
358 lists (\OPn{\VAR{ord-$\lambda$}}) and (\OPn{\VAR{method-combination-arg}})
359 according to \VAR{ord-$\lambda$} on p.\ \pageref{section:Functions}, the
360 latter enhanced by an optional \kwd{\&whole} argument.
363 \end{LIST}