开发者

Specifying multiple options in a structure's constructor?

开发者 https://www.devze.com 2023-04-05 06:33 出处:网络
I tried defining a structure with a custom print function and constructor like so: (defun print-test (a-test stream depth)

I tried defining a structure with a custom print function and constructor like so:

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

But on evaluation I get:

Bad defstruct option (:PRINT-FUNCTION PRINT-TEST :CONSTRUCTOR
                      CREATE-TEST (&KEY A B C)).
   [Condition of type CCL::SIMPLE-PROGRAM-ERROR]

But specifying either keyword alone works just fine. How can I fix this?


According to the grammar, options must be parenthesized individually. The defstruct form therefore needs to look like this:

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

精彩评论

暂无评论...
验证码 换一张
取 消