Debian Codegraph @

info/gcl/defmethod.html

raw
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2 <html>
3 <!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6 <title>defmethod (ANSI and GNU Common Lisp Document)</title>
7
8 <meta name="description" content="defmethod (ANSI and GNU Common Lisp Document)">
9 <meta name="keywords" content="defmethod (ANSI and GNU Common Lisp Document)">
10 <meta name="resource-type" content="document">
11 <meta name="distribution" content="global">
12 <meta name="Generator" content="makeinfo">
13 <link href="index.html" rel="start" title="Top">
14 <link href="Objects-Dictionary.html" rel="up" title="Objects Dictionary">
15 <link href="find_002dclass.html" rel="next" title="find-class">
16 <link href="defgeneric.html" rel="prev" title="defgeneric">
17 <style type="text/css">
18 <!--
19 a.summary-letter {text-decoration: none}
20 blockquote.indentedblock {margin-right: 0em}
21 div.display {margin-left: 3.2em}
22 div.example {margin-left: 3.2em}
23 div.lisp {margin-left: 3.2em}
24 kbd {font-style: oblique}
25 pre.display {font-family: inherit}
26 pre.format {font-family: inherit}
27 pre.menu-comment {font-family: serif}
28 pre.menu-preformatted {font-family: serif}
29 span.nolinebreak {white-space: nowrap}
30 span.roman {font-family: initial; font-weight: normal}
31 span.sansserif {font-family: sans-serif; font-weight: normal}
32 ul.no-bullet {list-style: none}
33 -->
34 </style>
35
36
37 </head>
38
39 <body lang="en">
40 <span id="defmethod"></span><div class="header">
41 <p>
42 Next: <a href="find_002dclass.html" accesskey="n" rel="next">find-class</a>, Previous: <a href="defgeneric.html" accesskey="p" rel="prev">defgeneric</a>, Up: <a href="Objects-Dictionary.html" accesskey="u" rel="up">Objects Dictionary</a> &nbsp; </p>
43 </div>
44 <hr>
45 <span id="defmethod-_005bMacro_005d"></span><h4 class="subsection">7.7.27 defmethod [Macro]</h4>
46
47 <p><code>defmethod</code> <i><i>function-name</i>
48 {<i>method-qualifier</i>}*
49 <i>specialized-lambda-list</i>
50 <span class="roman">[[{<i>declaration</i>}* | <i>documentation</i>]]</span> {<i>form</i>}*</i><br>
51 &rArr; <i>new-method</i>
52 </p>
53 <p><i>function-name</i>::= {<i>symbol</i>
54 | <tt>(setf <i>symbol</i>)</tt>}
55 </p>
56 <p><i>method-qualifier</i>::= <i>non-list</i>
57 </p>
58 <p>&nbsp;<i><span class="nolinebreak">specialized-lambda-list</span></i>::=&nbsp;({<i>var</i>&nbsp;|&nbsp;<span class="roman">(</span><span class="roman"><i>var</i>&nbsp;<i><span class="nolinebreak">parameter-specializer-name</span></i></span><span class="roman">)</span>}*<!-- /@w --><br>
59 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<tt>[</tt><span class="roman">&amp;optional</span>&nbsp;{<i>var</i>&nbsp;|&nbsp;<span class="roman">(</span>var&nbsp;<tt>[</tt><i>initform</i>&nbsp;<span class="roman"><span class="roman">[</span><i><span class="nolinebreak">supplied-p-parameter</span></i><span class="roman">]</span></span>&nbsp;<tt>]</tt><span class="roman">)</span>}*<tt>]</tt><!-- /@w --><br>
60 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<tt>[</tt><tt>&amp;rest</tt>&nbsp;<i>var</i><tt>]</tt><!-- /@w --><br>
61 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<tt>[</tt><span class="roman"><span class="roman">&amp;key</span></span>{<i>var</i>&nbsp;|&nbsp;<span class="roman">(</span>{<i>var</i>&nbsp;|&nbsp;<span class="roman">(</span><i>keyword</i><i>var</i><span class="roman">)</span>}&nbsp;<tt>[</tt><i>initform</i>&nbsp;<span class="roman">[</span><i><span class="nolinebreak">supplied-p-parameter</span></i><span class="roman">]</span>&nbsp;<tt>]</tt><span class="roman">)</span>}*<!-- /@w --><br>
62 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="roman">[</span><b><span class="nolinebreak">&amp;allow-other-keys</span></b><span class="roman">]</span>&nbsp;<tt>]</tt><!-- /@w --><br>
63 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<tt>[</tt><tt>&amp;aux</tt>&nbsp;{<i>var</i>&nbsp;|&nbsp;<span class="roman">(</span><i>var</i>&nbsp;<span class="roman">[</span><i>initform</i><span class="roman">]</span>&nbsp;<span class="roman">)</span>}*<tt>]</tt>&nbsp;<span class="roman">)</span><!-- /@w --><br>
64 </p>
65 <p>&nbsp;<i><span class="nolinebreak">parameter-specializer-name</span></i>::=&nbsp;<i>symbol</i>&nbsp;|&nbsp;<span class="roman">(</span><tt>eql</tt>&nbsp;<i><span class="nolinebreak">eql-specializer-form</span></i><span class="roman">)</span><!-- /@w --><br>
66 </p>
67 <span id="Arguments-and-Values_003a_003a-115"></span><h4 class="subsubheading">Arguments and Values::</h4>
68
69 <p><i>declaration</i>&mdash;a <b>declare</b> <i>expression</i>; not evaluated.
70 </p>
71 <p><i>documentation</i>&mdash;a <i>string</i>; not evaluated.
72 </p>
73 <p><i>var</i>&mdash;a <i>variable</i> <i>name</i>.
74 </p>
75 <p><i>eql-specializer-form</i>&mdash;a <i>form</i>.
76 </p>
77 <p><i>Form</i>&mdash;a <i>form</i>.
78 </p>
79 <p><i>Initform</i>&mdash;a <i>form</i>.
80 </p>
81 <p><i>Supplied-p-parameter</i>&mdash;variable name.
82 </p>
83 <p><i>new-method</i>&mdash;the new <i>method</i> <i>object</i>.
84 </p>
85 <span id="Description_003a_003a-154"></span><h4 class="subsubheading">Description::</h4>
86
87 <p>The macro <b>defmethod</b> defines a <i>method</i> on a
88 <i>generic function</i>.
89 </p>
90 <p>If <tt>(fboundp <i>function-name</i>)</tt> is <b>nil</b>, a
91 <i>generic function</i> is created with default values for
92 the argument precedence order
93 (each argument is more specific than the arguments to its right
94 in the argument list),
95 for the generic function class (the <i>class</i> <b>standard-generic-function</b>),
96 for the method class (the <i>class</i> <b>standard-method</b>),
97 and for the method combination type (the standard method combination type).
98 The <i>lambda list</i> of the <i>generic function</i> is
99 congruent with the <i>lambda list</i> of the
100 <i>method</i> being defined; if the
101 <b>defmethod</b> form mentions keyword arguments, the <i>lambda list</i> of
102 the <i>generic function</i>
103 will mention <tt>&amp;key</tt> (but no keyword
104 arguments). If <i>function-name</i> names
105 an <i>ordinary function</i>,
106 a <i>macro</i>, or a <i>special operator</i>,
107 an error is signaled.
108 </p>
109 <p>If a <i>generic function</i> is currently named by <i>function-name</i>,
110 the <i>lambda list</i> of the
111 <i>method</i> must be congruent with the <i>lambda list</i> of the
112 <i>generic function</i>.
113 If this condition does not hold, an error is signaled.
114 For a definition of congruence in this context, see <a href="Congruent-Lambda_002dlists-for-all-Methods-of-a-Generic-Function.html">Congruent Lambda-lists for all Methods of a Generic Function</a>.
115 </p>
116 <p>Each <i>method-qualifier</i> argument is an <i>object</i> that is used by
117 method combination to identify the given <i>method</i>.
118 The method combination type might further
119 restrict what a method <i>qualifier</i> can be.
120 The standard method combination type allows for <i>unqualified methods</i> and
121 <i>methods</i> whose sole
122 <i>qualifier</i> is one of the keywords <tt>:before</tt>, <tt>:after</tt>, or <tt>:around</tt>.
123 </p>
124 <p>The <i>specialized-lambda-list</i> argument is like an ordinary
125 <i>lambda list</i> except that the <i>names</i> of required parameters can
126 be replaced by specialized parameters. A specialized parameter is a
127 list of the form
128 <tt>(<i>var</i> <i>parameter-specializer-name</i>)</tt>.
129 Only required parameters can be
130 specialized. If <i>parameter-specializer-name</i> is a <i>symbol</i> it names a
131 <i>class</i>; if it is a <i>list</i>,
132 it is of the form <tt>(eql <i>eql-specializer-form</i>)</tt>. The parameter
133 specializer name <tt>(eql <i>eql-specializer-form</i>)</tt> indicates
134 that the corresponding argument must be <b>eql</b> to the <i>object</i> that
135 is the value of <i>eql-specializer-form</i> for the <i>method</i> to be applicable.
136 The <i>eql-specializer-form</i> is evaluated at the time
137 that the expansion of the <b>defmethod</b> macro is evaluated.
138 If no <i>parameter specializer name</i> is specified for a given
139 required parameter, the <i>parameter specializer</i> defaults to
140 the <i>class</i> <b>t</b>.
141 For further discussion, see <a href="Introduction-to-Methods.html">Introduction to Methods</a>.
142 </p>
143 <p>The <i>form</i> arguments specify the method body.
144 The body of the <i>method</i> is enclosed in an <i>implicit block</i>. If
145 <i>function-name</i> is a <i>symbol</i>,
146 this block bears the same <i>name</i> as the <i>generic function</i>.
147 If <i>function-name</i> is a <i>list</i> of the form
148 <tt>(setf <i>symbol</i>)</tt>, the <i>name</i> of the block is <i>symbol</i>.
149 </p>
150 <p>The <i>class</i> of the <i>method</i> <i>object</i> that is created is that given by the
151 method class option of the <i>generic function</i>
152 on which the <i>method</i> is defined.
153 </p>
154 <p>If the <i>generic function</i> already has a <i>method</i> that agrees with the
155 <i>method</i> being defined on <i>parameter specializers</i> and <i>qualifiers</i>,
156 <b>defmethod</b> replaces the existing <i>method</i> with the one now being
157 defined.
158 For a definition of agreement in this context.
159 see <a href="Agreement-on-Parameter-Specializers-and-Qualifiers.html">Agreement on Parameter Specializers and Qualifiers</a>.
160 </p>
161 <p>The <i>parameter specializers</i> are derived from
162 the <i>parameter specializer names</i> as described in
163 <a href="Introduction-to-Methods.html">Introduction to Methods</a>.
164 </p>
165 <p>The expansion of the <b>defmethod</b> macro &ldquo;refers to&rdquo; each
166 specialized parameter (see the description of <b>ignore</b>
167 within the description of <b>declare</b>).
168 This includes parameters that
169 have an explicit <i>parameter specializer name</i> of <b>t</b>. This means
170 that a compiler warning does not occur if the body of the <i>method</i> does
171 not refer to a specialized parameter, while a warning might occur
172 if the body of the <i>method</i> does not refer to an unspecialized parameter.
173 For this reason, a parameter that specializes on <b>t</b> is not quite synonymous
174 with an unspecialized parameter in this context.
175 </p>
176 <p>Declarations at the head of the method body that apply to the
177 method&rsquo;s <i>lambda variables</i> are treated as <i>bound declarations</i>
178 whose <i>scope</i> is the same as the corresponding <i>bindings</i>.
179 </p>
180 <p>Declarations at the head of the method body that apply to the
181 functional bindings of <b>call-next-method</b> or <b>next-method-p</b>
182 apply to references to those functions within the method body <i>forms</i>.
183 Any outer <i>bindings</i> of the <i>function names</i> <b>call-next-method</b> and
184 <b>next-method-p</b>, and declarations associated with such <i>bindings</i>
185 are <i>shadowed</i>_2 within the method body <i>forms</i>.
186 </p>
187 <p>The <i>scope</i> of <i>free declarations</i> at the head of the method body
188 is the entire method body,
189 which includes any implicit local function definitions
190 but excludes <i>initialization forms</i> for the <i>lambda variables</i>.
191 </p>
192 <p><b>defmethod</b> is not required to perform any compile-time side effects.
193 In particular, the <i>methods</i> are not installed for invocation during
194 compilation. An <i>implementation</i> may choose to store information about
195 the <i>generic function</i> for the purposes of compile-time error-checking
196 (such as checking the number of arguments on calls, or noting that a definition
197 for the function name has been seen).
198 </p>
199 <p><i>Documentation</i> is attached as a <i>documentation string</i>
200 to the <i>method</i> <i>object</i>.
201 </p>
202 <span id="Affected-By_003a_003a-14"></span><h4 class="subsubheading">Affected By::</h4>
203
204 <p>The definition of the referenced <i>generic function</i>.
205 </p>
206 <span id="Exceptional-Situations_003a_003a-39"></span><h4 class="subsubheading">Exceptional Situations::</h4>
207
208 <p>If <i>function-name</i> names an <i>ordinary function</i>,
209 a <i>macro</i>, or a <i>special operator</i>,
210 an error of <i>type</i> <b>error</b> is signaled.
211 </p>
212 <p>If a <i>generic function</i> is currently named by <i>function-name</i>,
213 the <i>lambda list</i> of the
214 <i>method</i> must be congruent with the <i>lambda list</i> of the
215 <i>generic function</i>, or
216 an error of <i>type</i> <b>error</b> is signaled.
217 </p>
218 <span id="See-Also_003a_003a-136"></span><h4 class="subsubheading">See Also::</h4>
219
220 <p><a href="defgeneric.html">defgeneric</a>
221 ,
222 <a href="documentation.html">documentation</a>
223 ,
224 <a href="Introduction-to-Methods.html">Introduction to Methods</a>,
225 <a href="Congruent-Lambda_002dlists-for-all-Methods-of-a-Generic-Function.html">Congruent Lambda-lists for all Methods of a Generic Function</a>,
226 <a href="Agreement-on-Parameter-Specializers-and-Qualifiers.html">Agreement on Parameter Specializers and Qualifiers</a>,
227 <a href="Syntactic-Interaction-of-Documentation-Strings-and-Declarations.html">Syntactic Interaction of Documentation Strings and Declarations</a>
228 </p>
229 <hr>
230 <div class="header">
231 <p>
232 Next: <a href="find_002dclass.html" accesskey="n" rel="next">find-class</a>, Previous: <a href="defgeneric.html" accesskey="p" rel="prev">defgeneric</a>, Up: <a href="Objects-Dictionary.html" accesskey="u" rel="up">Objects Dictionary</a> &nbsp; </p>
233 </div>
234
235
236
237 </body>
238 </html>