emacs.d/clones/www.sbcl.org/sbcl-internals/Method_002dBased-Discriminating-Functions.html

104 lines
5.5 KiB
HTML
Raw Normal View History

2023-01-18 20:30:47 +01:00
<html lang="en">
<head>
<title>Method-Based Discriminating Functions - SBCL Internals</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="SBCL Internals">
<meta name="generator" content="makeinfo 4.11">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Discriminating-Functions.html#Discriminating-Functions" title="Discriminating Functions">
<link rel="prev" href="The-Initial-Discriminating-Function.html#The-Initial-Discriminating-Function" title="The Initial Discriminating Function">
<link rel="next" href="Accessor-Discriminating-Functions.html#Accessor-Discriminating-Functions" title="Accessor Discriminating Functions">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
This manual is part of the SBCL software system. See the `README'
file for more information.
This manual is in the public domain and is provided with
absolutely no warranty. See the `COPYING' and `CREDITS' files for
more information.
-->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<p>
<a name="Method-Based-Discriminating-Functions"></a>
<a name="Method_002dBased-Discriminating-Functions"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="Accessor-Discriminating-Functions.html#Accessor-Discriminating-Functions">Accessor Discriminating Functions</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="The-Initial-Discriminating-Function.html#The-Initial-Discriminating-Function">The Initial Discriminating Function</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Discriminating-Functions.html#Discriminating-Functions">Discriminating Functions</a>
<hr>
</div>
<!-- node-name, next, previous, up -->
<h3 class="section">3.2 Method-Based Discriminating Functions</h3>
<p><a name="index-no_002dapplicable_002dmethod-3"></a>
The method-based discriminating functions are used if all the methods of
the generic function at the time of the first call are suitable:
therefore, these discriminating function strategies do not transition
into any of the other states unless the generic function is
reinitialized. Of these discriminating functions, the simplest is the
<code>SB-PCL::NO-METHODS</code>, which is appropriate when the generic
function has no methods. In this case, the discriminating function
simply performs an argument count check<a rel="footnote" href="Method_002dBased-Discriminating-Functions.html#fn-1" name="fnd-1"><sup>1</sup></a> and then calls
<code>NO-APPLICABLE-METHOD</code> with the appropriate arguments.
<p>If all of the specializers in all methods of the generic function are
the root of the class hierarchy, <code>t</code>, then no discrimination need
be performed: all of the methods are applicable on every
call<a rel="footnote" href="Method_002dBased-Discriminating-Functions.html#fn-2" name="fnd-2"><sup>2</sup></a>. In this case, the <code>SB-PCL::DEFAULT-METHOD-ONLY</code>
discriminating function can call the effective method directly, as it
will be the same for every generic function call.<a rel="footnote" href="Method_002dBased-Discriminating-Functions.html#fn-3" name="fnd-3"><sup>3</sup></a>
<p>If all methods of the generic function are known by the system to be
side-effect-free and return constants, and the generic function has
standard-method-combination and no eql-specialized methods, then the
<code>SB-PCL::CONSTANT-VALUE</code> discriminating function can simply cache
the return values for given argument types. Though this may initially
appear to have limited applicability, type predicates are usually of
this form, as in <a href="ex_003apred.html#ex_003apred">ex:pred</a><a rel="footnote" href="Method_002dBased-Discriminating-Functions.html#fn-4" name="fnd-4"><sup>4</sup></a>.
<div class="float">
<a name="ex_003apred"></a>
<pre class="example"> (defgeneric foop (x))
(defmethod foop ((foo foo)) t)
(defmethod foop (object) nil)
</pre>
<p><strong class="float-caption">Example 3.1</strong></p></div>
<p>More details of the cacheing mechanism are given in <a href="The-Cacheing-Mechanism.html#The-Cacheing-Mechanism">The Cacheing Mechanism</a> below.
<div class="footnote">
<hr>
<h4>Footnotes</h4><p class="footnote"><small>[<a name="fn-1" href="Method_002dBased-Discriminating-Functions.html#fnd-1">1</a>]</small> Actually, this bit
isn't currently done. Oops.</p>
<p class="footnote"><small>[<a name="fn-2" href="Method_002dBased-Discriminating-Functions.html#fnd-2">2</a>]</small> Hm, there might be another problem with argument count
here.</p>
<p class="footnote"><small>[<a name="fn-3" href="Method_002dBased-Discriminating-Functions.html#fnd-3">3</a>]</small> I wonder if
we're invalidating this right if we define a method on
compute-applicable-methods...</p>
<p class="footnote"><small>[<a name="fn-4" href="Method_002dBased-Discriminating-Functions.html#fnd-4">4</a>]</small> There is vestigial code in SBCL
for a currently unused specialization of <code>SB-PCL::CONSTANT-VALUE</code>
for boolean values only.</p>
<hr></div>
</body></html>