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

Bug in COMPUTE-EFFECTIVE-METHOD?



There appears to be a bug in the definition of
COMPUTE-EFFECTIVE-METHOD, specifically in line 2716 of clos.lsp:

      (loop (apply #'no-applicable-method gf args))

You can see that if a programmer defines new methods for
NO-APPLICABLE-METHOD, and if the resulting effective method returns to
its caller, an endless loop will result.  So maybe this line should
be:

      (apply #'no-applicable-method gf args)

When I make this change, my NO-APPLICABLE-METHOD no longer loops
endlessly, but then NO-PRIMARY-METHOD signals an error "no primary
method is applicable", as if to remind me that the empty set has no
members :-)

Question: Is NO-PRIMARY-METHOD specific to CLISP (I can't find it in
          dpANS)?

Question: Shouldn't NO-PRIMARY-METHOD be called only when there _are_
          applicable methods?  Semantically speaking, this makes more
          sense to me, since then the calling of NO-PRIMARY-METHOD
          would represent new information about the state of the
          system. In other words, if NO-APPLICABLE-METHOD has been
          called, then calling NO-PRIMARY-METHOD won't tell me
          anything I don't already know!

Remark:   In line 2761 of clos.lsp, you see that that programmer
          defined methods for NO-PRIMARY-METHOD might also loop
          endlessly.  So, assuming that such programmer-defined
          methods are allowed, this is another instance of the same
          bug. 


Here's my test code (latest version of CLISP):

--------cut------------
(defclass foo () ())
(defmethod foo-id ((self foo) &rest ignore) self)
(defmethod no-applicable-method ((fn (eql #'foo-id)) &rest args)
   (format T "~&~S~S~%" fn args))
--------cut------------

;;   this works okay
> (foo-id (make-instance 'foo))
#<FOO #x000014>

;;   this results in an endless loop
> (foo-id 42 'a 'b)
#<GENERIC-FUNCTION FOO-ID>(42 A B)
#<GENERIC-FUNCTION FOO-ID>(42 A B)
#<GENERIC-FUNCTION FOO-ID>(42 A B)
         ...

One more minor thing: When I define a new method for
internally-defined generic functions (such as NO-APPLICABLE-METHOD), I
get the

     WARNING: The generic function
        #<GENERIC-FUNCTION NO-APPLICABLE-METHOD>
        is being modified, but has already been called.

Question: Is this wording misleading?  It would seem so, since the
          default NO-APPLICABLE-METHOD would signal an error, and
          merely defining a new method for NO-APPLICABLE-METHOD
          doesn't signal such an error.

Thanks!

Mark A. Thomas
thommark@access.digex.net