[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: generic-function-effective-method?

    Date: Wed, 12 Oct 88 16:14:16 -0400
    From: kanderso@PEBBLES.BBN.COM

    The CLOS MOP doesn't define a function like
    GENERIC-FUNCTION-EFFECTIVE-METHOD, though i think it would be quite
    easy to do and fairly useful:

Yes, it is useful, your two examples are not uncommon.  It is easy
enough to write using chapter 3 stuff that we don't provide it all
packaged up.  Another reason is that sometimes you want the "effective
method", and sometimes you want a function you can apply.

(defmethod generic-function-effective-method
	   ((gf standard-generic-function) args)
  (let ((combin (generic-function-method-combination gf))
	(methods (compute-applicable-methods gf args)))
    (compute-effective-method gf combin methods)))

    PCL avoids doing this at all cost, in fact it tries to combine
    discrimination and effective method application as tightly as
    possible.  However, a programmer might occasionally use this:

    EXAMPLE 1:  Pull discrimination out of a loop:

    ;;; Rather than:
    (dotimes (i 10000)
      (generic-frob object))

    ;;; One could write:
    (let ((m (generic-function-effective-method generic-frob object)))
      (dotimes (i 10000)
	(funcall m object)))  ; Hope no one is redefining generic-frob.

    OK, so ideally where only saving a few instructions, BUT they can
    add up. 

In order to do this, you would have to do some other playing around.
The "effective method" itself is not a function that can be called.
You make it into a function using make-method-function.  Then you
can call it using apply-method-function.