COERCE
does not work with CLOS objects. You can change the class of an instance with CHANGE-CLASS
, but that's usually not a good idea.
CALL-NEXT-METHOD
You can call the next applicable method: CALL-NEXT-METHOD
. Note that you can't call a specific method that way, just the next one. Most of the time this is what one would use in CLOS. The task is then during method definition to set up the generic function in such a way, using primary, :around
, :before
and :after
methods, that the right behavior emerges.
Calling specific functions when all else fails
There is an esoteric way to call a specific method:
(funcall (method-function (find-method #'print-object
nil
(list (find-class 'a)
(find-class t))))
(make-instance 'b)
t)
In above code, the function METHOD-FUNCTION
is not part of ANSI Common Lisp, but provided in many implementations by the Metaobject Protocol (MOP).