有没有办法找到专门针对给定类型的所有函数?
我设想你可以从repl执行的东西(find-all-specializing-methods 'my-class),它将返回一个方法列表,如(mypackage1:my-method-1 my-package2:my-method-2 etc.)
我认为必须有一个简单的方法来做到这一点,因为MOP本身可能需要存储这样的列表来决定调用哪些方法.
小智 5
为了找到您可以查看slime-who-specializes并了解如何为您的设置执行此操作.
根据定义,我到目前为止(对于SBCL):
#+#.(swank-backend::sbcl-with-xref-p)
(progn
(defmacro defxref (name &optional fn-name)
`(defimplementation ,name (what)
(sanitize-xrefs
(mapcar #'source-location-for-xref-data
(,(find-symbol (symbol-name (if fn-name
fn-name
name))
"SB-INTROSPECT")
what)))))
(defxref who-calls)
(defxref who-binds)
(defxref who-sets)
(defxref who-references)
(defxref who-macroexpands)
#+#.(swank-backend:with-symbol 'who-specializes-directly 'sb-introspect)
(defxref who-specializes who-specializes-directly))
Run Code Online (Sandbox Code Playgroud)
此功能是针对不同的Lisp单独实现的,因此如果您需要特定的详细信息,则需要查看:swank-<your lisp>.lispfile并搜索who-specializes泛型函数的实现.