基于Common Lisp Object System类定义中的其他槽值初始化槽

Pau*_*ers 6 common-lisp clos slot

在我的类定义中,我想基于另一个槽的值初始化一个槽.这是我想做的事情:

(defclass my-class ()
  ((slot-1 :accessor my-class-slot-1 :initarg slot-1)
   (slot-2 :accessor my-class-slot-2 :initform (list slot-1))))
Run Code Online (Sandbox Code Playgroud)

但是这不会编译:

1 compiler notes:

Unknown location:
  warning: 
    This variable is undefined:
      SLOT-1

  warning: 
    undefined variable: SLOT-1
    ==>
      (CONS UC-2::SLOT-1 NIL)


Compilation failed.
Run Code Online (Sandbox Code Playgroud)

有没有办法做到这一点?

Dou*_*rie 3

使用此处initialize-instance :after记录的