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

Re: methods dispatching ????



On Oct 28,  6:53pm, mathieu Lafourcade wrote:
> In clos, I define a class C which inherits from two classes : C (A B).
> 
> C has a method M.
> 
> In the call M(C), I want to call alternatively the next-method M(A) or M(C).
> Something like :
> 
> (defmethod M (C)
>         (if condition (call-next-method A)
>                       (call-next-method B)
>         ))

As I understand it, I don't think you can do this, since you can't
change the set of methods which are considered by call-next-method.
However, you could add a keyword argument to the call via
call-next-method so that the methods on A & B can determine whether they
should do anything.  E.g., something like:

(defmethod M ((self A) &KEY situation)
  (when (eq situation 'A)
    (do-something)))

(defmethod M ((self B) &KEY situation)
  (when (eq situation 'B)
    (do-something-else)))

(defmethod M ((self C) &REST rest &KEY situation)
  (apply #'call-next-method
	 self
	 :situation (if (condition) 'A 'B)
	 rest))

Even if the original generic call to M included a :situation, the C
method's value would override it, since only the first occurrence of a
keyword is used.

George Williams            BCS Huntsville Artificial Intelligence Center
Boeing Computer Services   Internet: george@hsvaic.boeing.com
POBox 240002, M/S JY-58    UUCP: ...!uw-beaver!bcsaic!hsvaic!george
Huntsville AL 35824-6402   Phone: 205+464-4968 FAX: 205+464-4930