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を生成する関数を定義する簡単な方法はありますか? つまり、すべてのスロットを次のようにリストする必要はありません。BARC

(defun make-bar-from-foo (existing-foo c)
  (make-instance 'bar :a (a existing-foo) :b (b existing-foo) :c c))
4

1 に答える 1

0

これはオプションかもしれません:

(defclass foo ()
  ((a :initarg :a :accessor a)
   (b :initarg :b :accessor b)
   (initargs :accessor initargs))) ;Remember the initargs here.

(defclass bar (foo)
  ((c :initarg :c :accessor c)))

(defmethod initialize-instance :after ((foo foo) &rest initargs)
  (setf (initargs foo) initargs))

(defun make-bar-from-foo (foo c)
  (apply #'make-instance 'bar :c c (initargs foo))) ;And use them here.
于 2015-08-17T09:12:13.393 に答える