我有一个非常简单的数据结构,我在Lisp中定义:
;;Data structure for a person
(defstruct person
(name nil)
(age 0)
(siblings nil :type list)) ;; Siblings is a list of person objects
Run Code Online (Sandbox Code Playgroud)
然后我继续实例化一些人物:
(setf person-a (make-person :name 'Tim :age 23))
(setf person-b (make-person :name 'Sally :age 21))
(setf person-c (make-person :name 'Louis :age 24))
Run Code Online (Sandbox Code Playgroud)
然后,我将兄弟姐妹联系起来(假设他们都是彼此的兄弟姐妹):
(setf (person-siblings person-a) (list person-b person-c))
(setf (person-siblings person-b) (list person-a person-c))
(setf (person-siblings person-c) (list person-b person-a))
Run Code Online (Sandbox Code Playgroud)
然后,我如何打印有关我已实例化和修改的对象的信息?我已经研究了关于print-object和print-function的defstruct选项,但我无法弄清楚如何正确打印我的对象.使用类似的东西:
(print person-a)
Run Code Online (Sandbox Code Playgroud)
将我的ACL解释器发送到无限循环.