基于Common Lisp对象系统类定义中的其他槽值初始化槽 [英] Initializing slots based on other slot values in Common Lisp Object System class definitions

查看:0
本文介绍了基于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.

有办法做到这一点吗?

推荐答案

使用initialize-instance :after文档here

这篇关于基于Common Lisp对象系统类定义中的其他槽值初始化槽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆