(defclass a () ())
a
(defclass b (a) ())
b
(cl-defmethod foo ((o a))
(princ "a base\n")
nil)
foo
(foo (make-instance 'b))
a base
(cl-defmethod foo :after ((o a))
(princ "a after\n"))
foo
(foo (make-instance 'b))
a base
a after
nil
(cl-defmethod foo :around ((o b))
(funcall (cl--generic-method-function
(cl-find-method #'foo '() '(a)))
o))
foo
(foo (make-instance 'b))
a base
nil
最后一个用的 cl--generic-method-function 是 emacs lisp specific 的 internal function,非常 dirty,你也可以直接 copy method on a 的 definition。
Common Lisp 是有 method combination 的,然而 eieio 这个重度鶸化版沒有这功能。
<#lisp> beach: ldbeth: If doing something like that is necessary, then there is something seriously wrong with the protocol design.