Next: , Previous: The Initial Discriminating Function, Up: Discriminating Functions

3.2 Method-Based Discriminating Functions

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 SB-PCL::NO-METHODS, which is appropriate when the generic function has no methods. In this case, the discriminating function simply performs an argument count check1 and then calls NO-APPLICABLE-METHOD with the appropriate arguments.

If all of the specializers in all methods of the generic function are the root of the class hierarchy, t, then no discrimination need be performed: all of the methods are applicable on every call2. In this case, the SB-PCL::DEFAULT-METHOD-ONLY discriminating function can call the effective method directly, as it will be the same for every generic function call.3

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 SB-PCL::CONSTANT-VALUE 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 ex:pred4.

     (defgeneric foop (x))
     (defmethod foop ((foo foo)) t)
     (defmethod foop (object) nil)

Example 3.1

More details of the cacheing mechanism are given in The Cacheing Mechanism below.


[1] Actually, this bit isn't currently done. Oops.

[2] Hm, there might be another problem with argument count here.

[3] I wonder if we're invalidating this right if we define a method on compute-applicable-methods...

[4] There is vestigial code in SBCL for a currently unused specialization of SB-PCL::CONSTANT-VALUE for boolean values only.