2011-09-17 85 views
2

我試圖定義一個自定義打印功能和構造的結構如下所示:在結構的構造函數中指定多個選項?

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

但指定是關鍵字單獨的作品就好了。我怎樣才能解決這個問題?

回答

2

根據grammar,選項必須單獨加上括號。 defstruct表格因此需要如下所示:

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