在结构的构造函数中指定多个选项?

时间:2011-09-17 04:02:12

标签: lisp common-lisp syntax-error

我尝试使用自定义打印功能和构造函数定义结构,如下所示:

(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]

但是单独指定任一关键字都可以。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

根据grammar,选项必须单独括号。因此,defstruct表单需要如下所示:

(defstruct (test-struct (:print-function print-test)
                        (:constructor create-test (&key a (b a) c)))
  a
  b
  c)