小编def*_*dle的帖子

使用不同参数列表"重载"CLOS多方法

我试图在Common Lisp中对多方法进行"重载调用".这是案例的简化纲要:

(defclass foo ()
  ((slotty :accessor slotty :initarg :slotty)))

(defclass bar ()
  ((slotty :accessor slotty :initarg :slotty)))

(defparameter *foo* (make-instance 'foo :slotty "defnoodle"))
(defparameter *bar* (make-instance 'bar :slotty "Chocolate"))

(defmethod contrived ((f foo) (b bar))
  (format t "i pity the foo ~A, who has a bar ~A ~%" (slotty f) (slotty b)))

(contrived *foo* *bar*)
Run Code Online (Sandbox Code Playgroud)

输出: i pity the foo defnoodle, who has a bar Chocolate

但是一旦我尝试定义下一个方法:

 (defmethod contrived ((f foo))
    (format  t "i just pity the foo ~A …
Run Code Online (Sandbox Code Playgroud)

lisp common-lisp clos

3
推荐指数
1
解决办法
334
查看次数

标签 统计

clos ×1

common-lisp ×1

lisp ×1