有没有办法从 Common Lisp 中的泛型函数中提取方法列表?
例如:
(defmethod say ((self string)) ; method-0
(format t "Got string: ~a~%" self))
(defmethod say ((self integer)) ; method-1
(format t "Got integer: ~a~%" self))
(defmethod say ((self symbol)) ; method-2
(format t "Got symbol: ~a~%" self))
(extract-methods-from-generic 'say) ; -> (method-0-obj method-1-obj method-2-obj)
更具体地说,我的目标是 ECL,所以如果这可以通过 C API 完成 - 没关系。
我需要这个来做下一个技巧:
(defgeneric merged-generic ())
(loop for method
in (extract-methods-from-generic 'some-generic-0)
do (add-method merged-generic method))
(loop for method
in (extract-methods-from-generic 'some-generic-1)
do (add-method merged-generic method))