1
所以我有类使用超类的构造函数?
(defclass foo()
((a :initarg :a :accessor a)
(b :initarg :b :accessor b)))
(defclass bar (foo)
((c :initarg :c)))
和构造函数
(defun make-foo (a b)
(make-instance 'foo :a a :b b))
有没有一种简单的方法来定义一个函数,它在现有的FOO
并产生BAR
与额外的插槽C
定义?即而不必列出所有插槽例如:
(defun make-bar-from-foo (existing-foo c)
(make-instance 'bar :a (a existing-foo) :b (b existing-foo) :c c))
没有什么内置。你确定你不想只用'CHANGE-CLASS'将existing-foo改成'bar'吗? – Barmar
@Barmar哦,不知道'CHANGE-CLASS',谢谢! – wrongusername
CLOS本身没有构造函数。如果你想要的是一个新的'bar'对象,'change-class'可能不是你想要的,因为它实际上改变了对象。 – Vatine