我尝试使用自定义打印功能和构造函数定义结构,如下所示:
(defun print-test (a-test stream depth)
(format stream "#<TEST-STRUCT ~A>" (test-struct-a a-test)))
(defstruct (test-struct (:print-function print-test
:constructor create-test
(&key a (b a) c)))
a
b
c)
但是在评估中我得到了:
Bad defstruct option (:PRINT-FUNCTION PRINT-TEST :CONSTRUCTOR
CREATE-TEST (&KEY A B C)).
[Condition of type CCL::SIMPLE-PROGRAM-ERROR]
但是单独指定任一关键字都可以。我该如何解决这个问题?
答案 0 :(得分:2)
根据grammar,选项必须单独括号。因此,defstruct
表单需要如下所示:
(defstruct (test-struct (:print-function print-test)
(:constructor create-test (&key a (b a) c)))
a
b
c)