我已将以下方法添加到泛型函数中,speak但现在想在REPL中删除此特定方法,而不删除其余的泛型函数的方法。
(defmethod speak :around ((c courtier) string) ; [1]
(format t "Does the King believe that ~A?" string)
(if (eql (read) 'yes)
(if (next-method-p) (call-next-method)) ; [2]
(format t "Indeed, it is a preposterous idea.~%"))
'bow)
[1] The :around method replaces the primary method for the type.
[2] Then it decides whether to call the primary method or not.
Run Code Online (Sandbox Code Playgroud)
该函数的文档链接remove-method没有示例,我不知道引用:around上面实际方法的语法是什么。
(remove-method #'speak)
TOO FEW ARGUMENTS
(remove-method #'speak :around)
NO-APPLICABLE-METHOD
Run Code Online (Sandbox Code Playgroud)
从文档中:
删除方法通用函数方法
它期望一个泛型函数对象和一个方法对象作为参数。
可以通过找到方法find-method。
CL-USER 39 > (find-method #'speak
(list :around)
(list (find-class 'courtier) (find-class t)))
#<STANDARD-METHOD SPEAK (:AROUND) (COURTIER T) 42001285EB>
CL-USER 40 > (remove-method #'speak
(find-method #'speak
(list :around)
(list (find-class 'courtier)
(find-class t))))
#<STANDARD-GENERIC-FUNCTION SPEAK 422000A68C>
Run Code Online (Sandbox Code Playgroud)
还请注意,良好的Lisp开发环境也可能允许删除编辑器或检查器中的方法。
请注意,在Lisp侦听器中,不需要find-method像上面那样调用两次。该变量*包含最后一个结果。
CL-USER 43 > (find-method #'speak
(list :around)
(list (find-class 'courtier)
(find-class t)))
#<STANDARD-METHOD SPEAK (:AROUND) (COURTIER T) 4200150DEB>
CL-USER 44 > (remove-method #'speak *)
#<STANDARD-GENERIC-FUNCTION SPEAK 422000A68C>
Run Code Online (Sandbox Code Playgroud)
这是另一个在GNU Emacs中使用SLIME并启用了SLIME 演示功能的交互示例。甲介绍是Lisp的输出,这使印刷物和所生成的文本之间的连接。
调用该find-method函数。它返回方法。在这里,我们使用presentations来保持文本和Lisp对象之间的连接。输出显示为红色,并且对鼠标敏感。将鼠标移到红色的返回对象上将添加交互选项。
现在(remove-method #'speak,在红色输出上键入然后单击鼠标中键(或配置为使用SLIME的任何工具):演示文稿(文本和连接的对象)将复制到该行。输入)和输入的形式。那么,SLIME实际上是用实际对象而不是文本表示构造的列表。
这就是repls在Symbolics Lisp机器和CLIM / McCLIM中的工作方式...