【发布时间】:2013-06-26 16:31:42
【问题描述】:
我正在尝试通过另一个结构实例或其名称访问结构实例的字段。诚然,这听起来很令人困惑,我有一个(非常结构化的)示例:
(defstruct author
(name nil)
(books '())
(years '()))
(defstruct book
(name nil)
(author '())
(copy-sold '()))
(defparameter hitchikers-guide
(make-book :name "Hitchikers-Guide"
:author '(douglas-adams)
:copy-sold '(a lot)))
(defparameter douglas-adams
(make-author :name "Douglas Adams"
:books '(Hitchikers-guide restaurant life-and-universe fish)
:years '(too few)))
(defparameter authors
'(douglas-adams pterry))
我有实例hitchikers-guide。如果我想查找其作者的所有书籍,我可以输入 REPL (author-books douglas-adams),然后我会得到他所有书籍的列表。但是,如果我输入
(author-books (first (book-author hitchikers-guide)))
或
(author-books (first authors))
我收到错误消息:
值 DOUGLAS-ADAMS 不是预期的 AUTHOR 类型。
是我做错了,还是无法以这种方式访问这些字段?
【问题讨论】:
标签: lisp common-lisp