根据 Common Lisp 对象系统类定义中的其他槽值初始化槽
在我的类定义中,我想根据另一个槽的值初始化一个槽。这是我想做的事情:
(defclass my-class ()
((slot-1 :accessor my-class-slot-1 :initarg slot-1)
(slot-2 :accessor my-class-slot-2 :initform (list slot-1))))
但是这不能编译:
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.
有办法做到这一点吗?
In my class definition, I want to initialize one slot based on the value of another slot. Here is the sort of thing I would like to do:
(defclass my-class ()
((slot-1 :accessor my-class-slot-1 :initarg slot-1)
(slot-2 :accessor my-class-slot-2 :initform (list slot-1))))
However this doesn't compile:
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.
Is there a way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用此处记录的
initialize-instance :after
< /a>Use
initialize-instance :after
documented here这是 Doug Currie 的答案扩展:
这是一个显示它有效的调用:
请参阅 这篇文章了解更多详情。
Here is Doug Currie's answer expanded:
Here's a call showing that it works:
See this article for more details.