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)
精彩评论