#|
Hello,
Suppose I have three classes, class-a, class-b, and class-c,
in a simple single-inheritance hierarchy. There is a
generic function, call it gf, with methods specializing
on class-a and class-b. I have no access to, i.e. cannot
redefine, the class-a and class-b methods of gf. Now I
need to specialize gf on class-c in such a way that
the class-a method is called first and the class-b
method is bypassed completely. I came up with two
solutions both using the :before qualifier: one with find-method,
the other with change-class. But I can't get rid of the
feeling that I simply concocted a hack. Is there a more
elegant way to solve this problem in Allegro CLOS?
|#
(defclass class-a () ())
(defclass class-b (class-a) ())
(defclass class-c (class-b) ())
(defgeneric gf (x))
(defmethod gf ((x class-a))
(format t "gf on class-a~%"))
(defmethod gf ((x class-b))
(format t "gf on class-b~%"))
;;; 1st solution
(defmethod gf :before ((x class-c))
(let* ((gf (symbol-function 'gf))
(m (find-method gf '() (list (find-class 'class-a)))))
(funcall (clos:method-function m) x)))
#|
;;; 2nd solution
(defmethod gf :before ((x class-c))
(unwind-protect
(progn
(change-class x 'class-a)
(gf x))
(change-class x 'class-c)))
|#
(defmethod gf ((x class-c))
(format t "gf on class-c"))
;;; Thank you and excuse my ignorance,
;;; VK