emacs.d/clones/lisp/www.cs.cmu.edu/Groups/AI/html/cltl/clm/node282.html

91 lines
4.8 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
<!Converted with LaTeX2HTML 0.6.5 (Tue Nov 15 1994) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
<HEAD>
<TITLE>28.1.6.5. Keyword Arguments in Generic Functions and Methods</TITLE>
</HEAD>
<BODY>
<meta name="description" value=" Keyword Arguments in Generic Functions and Methods">
<meta name="keywords" value="clm">
<meta name="resource-type" value="document">
<meta name="distribution" value="global">
<P>
<b>Common Lisp the Language, 2nd Edition</b>
<BR> <HR><A NAME=tex2html5181 HREF="node283.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html5179 HREF="node277.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html5175 HREF="node281.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html5183 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html5184 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME=tex2html5182 HREF="node283.html"> Method Selection and </A>
<B>Up:</B> <A NAME=tex2html5180 HREF="node277.html"> Generic Functions and </A>
<B> Previous:</B> <A NAME=tex2html5176 HREF="node281.html"> Congruent Lambda-Lists for </A>
<HR> <P>
<H3><A NAME=SECTION003216500000000000000>28.1.6.5. Keyword Arguments in Generic Functions and Methods</A></H3>
<P>
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
When a generic function or any of its methods mentions <tt>&amp;key</tt> in
a lambda-list, the specific set of keyword arguments accepted by the
generic function varies according to the applicable methods. The set
of keyword arguments accepted by the generic function for a particular
call is the union of the keyword arguments accepted by all applicable
methods and the keyword arguments mentioned after <tt>&amp;key</tt> in the
generic function definition, if any. A method that has <tt>&amp;rest</tt>
but not <tt>&amp;key</tt> does not affect the set of acceptable keyword
arguments. If the lambda-list of any applicable method or of the
generic function definition contains <tt>&amp;allow-other-keys</tt>, all
keyword arguments are accepted by the generic function.
<P>
The lambda-list congruence rules require that each method
accept all of the keyword arguments mentioned after <tt>&amp;key</tt> in the
generic function definition, by accepting them explicitly, by
specifying <tt>&amp;allow-other-keys</tt>, or by specifying <tt>&amp;rest</tt> but
not <tt>&amp;key</tt>. Each method can accept additional keyword arguments
of its own, in addition to the keyword arguments mentioned in the
generic function definition.
<P>
<P>
If a generic function is passed a keyword argument that no applicable
method accepts, an error is signaled.
<P>
For example, suppose there are two methods defined for <tt>width</tt>
as follows:
<P>
<P><pre>
(defmethod width ((c character-class) &amp;key font) ...)
(defmethod width ((p picture-class) &amp;key pixel-size) ...)
</pre><P>
<P>
Assume that there are no other methods and no generic
function definition for <tt>width</tt>. The evaluation of the
following form will signal an error because the keyword argument
<tt>:pixel-size</tt> is not accepted by the applicable method.
<P>
<P><pre>
(width (make-instance 'character-class :char #\Q)
:font 'baskerville :pixel-size 10)
</pre><P>
<P>
The evaluation of the following form will signal an error.
<P>
<P><pre>
(width (make-instance 'picture-class :glyph (glyph #\Q))
:font 'baskerville :pixel-size 10)
</pre><P>
<P>
The evaluation of the following form will not signal an error
if the class named <tt>character-picture-class</tt> is a subclass of
both <tt>picture-class</tt> and <tt>character-class</tt>.
<P>
<P><pre>
(width (make-instance 'character-picture-class :char #\Q)
:font 'baskerville :pixel-size 10)
</pre><P>
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
<P>
<BR> <HR><A NAME=tex2html5181 HREF="node283.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html5179 HREF="node277.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html5175 HREF="node281.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html5183 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html5184 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME=tex2html5182 HREF="node283.html"> Method Selection and </A>
<B>Up:</B> <A NAME=tex2html5180 HREF="node277.html"> Generic Functions and </A>
<B> Previous:</B> <A NAME=tex2html5176 HREF="node281.html"> Congruent Lambda-Lists for </A>
<HR> <P>
<HR>
<P><ADDRESS>
AI.Repository@cs.cmu.edu
</ADDRESS>
</BODY>