我想在类对象上定义方法,这些方法基于类的祖先继承,就像实例的方法继承一样。有没有办法做到这一点?
这是不起作用的:eql-方法专业化。考虑这个例子:
(defclass animal ()())
(defclass bird (animal)())
(defclass woodpecker (bird)())
(defmethod wings-p ((animal-class (eql (find-class 'animal)))) nil)
(defmethod wings-p ((bird-class (eql (find-class 'bird)))) t)
调用会(wings-p (find-class 'woodpecker))生成一个no-method-error,您可以看到为什么 - classwoodpecker显然不是eql任何方法专家。
我想在 on 上定义“方法” bird,animal以便当我调用wings-pon时(find-class woodpecker),wings-p返回t。
我觉得这是几乎所有其他 OO 系统的标准功能,但我不记得如何使用 CLOS 来做到这一点。