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

122 lines
6.9 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.7.4. Built-in Method Combination Types</TITLE>
</HEAD>
<BODY>
<meta name="description" value=" Built-in Method Combination Types">
<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=tex2html5243 HREF="node288.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html5241 HREF="node283.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html5237 HREF="node286.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html5245 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html5246 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME=tex2html5244 HREF="node288.html"> Meta-objects</A>
<B>Up:</B> <A NAME=tex2html5242 HREF="node283.html"> Method Selection and </A>
<B> Previous:</B> <A NAME=tex2html5238 HREF="node286.html"> Declarative Method Combination</A>
<HR> <P>
<H3><A NAME=SECTION003217400000000000000>28.1.7.4. Built-in Method Combination Types</A></H3>
<P>
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
<A NAME=BuiltinMethodCombinationTypesSECTION>The</A>
Common Lisp Object System provides a set of built-in method combination types. To
specify that a generic function is to use one of these method
combination types, the name of the method combination type is given as
the argument to the <tt>:method-combination</tt> option to
<tt>defgeneric</tt> or to the <tt>:method-combination</tt> option to any of the
other forms that specify generic function options.
<P>
The names of the built-in method combination types are
<tt>+</tt>, <tt>and</tt>, <tt>append</tt>, <tt>list</tt>, <tt>max</tt>, <tt>min</tt>,
<tt>nconc</tt>, <tt>or</tt>, <tt>progn</tt>, and <tt>standard</tt>.
<P>
The semantics of the <tt>standard</tt> built-in method combination type were
described in section <A HREF="node285.html#StandardMethodCombinationSECTION">28.1.7.2</A>. The other
built-in method combination types are called <i>simple built-in method
combination types.</i>
<P>
The simple built-in method combination types act as though they were
defined by the short form of <tt>define-method-combination</tt>. They
recognize two roles for methods:
<P>
<UL><LI> An <tt>:around</tt> method has the keyword symbol
<tt>:around</tt> as its sole qualifier. The meaning of <tt>:around</tt>
methods is the same as in standard method combination. Use of the
functions <tt>call-next-method</tt> and <tt>next-method-p</tt> is supported
in <tt>:around</tt> methods.
<P>
<LI> A primary method has the name of the method combination
type as its sole qualifier. For example, the built-in method
combination type <tt>and</tt> recognizes methods whose sole qualifier is
<tt>and</tt>; these are primary methods. Use of the functions
<tt>call-next-method</tt> and <tt>next-method-p</tt> is not supported in primary
methods.
<P>
</UL>
The semantics of the simple built-in method combination types are as
follows:
<P>
<UL><LI>
If there are any <tt>:around</tt> methods, the most specific <tt>:around</tt>
method is called. It supplies the value or values of the generic function.
<P>
<LI> Inside the body of an <tt>:around</tt> method, the function
<tt>call-next-method</tt> can be used to call the next method. The
generic function <tt>no-next-method</tt> is invoked if
<tt>call-next-method</tt> is used and there is no applicable method to call.
The function <tt>next-method-p</tt> may be used to determine whether a
next method exists. When the next method returns, the <tt>:around</tt>
method can execute more code, perhaps based on the returned value or
values.
<P>
<LI> If an <tt>:around</tt> method invokes
<tt>call-next-method</tt>, the next most specific <tt>:around</tt> method is
called, if one is applicable. If there are no <tt>:around</tt> methods
or if <tt>call-next-method</tt> is called by the least specific
<tt>:around</tt> method, a Lisp form derived from the name of the built-in
method combination type and from the list of applicable primary
methods is evaluated to produce the value of the generic function.
Suppose the name of the method combination type is <i>operator</i>
and the call to the generic function is of the form
<P><pre>
(<i>generic-function</i> <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap42265.gif"> ... <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap40275.gif">)
</pre><P>
Let <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43597.gif"> be the applicable primary methods
in order; then the derived Lisp form is
<P><pre>
(<i>operator</i> <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43599.gif">
... <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43601.gif">)
</pre><P>
If the expression <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43603.gif"> is
evaluated, the method <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43605.gif"> will be applied to the arguments
<IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43607.gif">.
For example,
if <i>operator</i> is <tt>or</tt>,
the expression <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43609.gif"> is
evaluated only if <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap43611.gif">,
1 &lt;= <i>j</i> &lt; <i>i</i>, returned <tt>nil</tt>.
<P>
The default order for the primary methods is
<tt>:most-specific-first</tt>. However, the order can be reversed by supplying
<tt>:most-specific-last</tt> as the second argument to the
<tt>:method-combination</tt> option.
<P>
</UL>
<P>
The simple built-in method combination types require exactly one qualifier per
method. An error is signaled if there are applicable methods with no
qualifiers or with qualifiers that are not supported by the method
combination type. An error is signaled if there are applicable <tt>:around</tt>
methods and no applicable primary methods.
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
<P>
<BR> <HR><A NAME=tex2html5243 HREF="node288.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html5241 HREF="node283.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html5237 HREF="node286.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html5245 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html5246 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME=tex2html5244 HREF="node288.html"> Meta-objects</A>
<B>Up:</B> <A NAME=tex2html5242 HREF="node283.html"> Method Selection and </A>
<B> Previous:</B> <A NAME=tex2html5238 HREF="node286.html"> Declarative Method Combination</A>
<HR> <P>
<HR>
<P><ADDRESS>
AI.Repository@cs.cmu.edu
</ADDRESS>
</BODY>