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

标签 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]

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

最佳答案

根据grammar , 选项必须单独用括号括起来。因此,defstruct 形式需要如下所示:

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

关于lisp - 在结构的构造函数中指定多个选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7452353/

相关文章:

Lisp 参数指针

scheme - Racket 如何处理(定义(f(x y))主体)?

emacs - 在 emacs 中添加新代码时重新缩进 lisp 代码

arrays - 具有良好多维数组编程支持的 Lispy 方言

c++ - C++ : "error: int aaa::bbb is protected within this context" 上的错误

emacs - 如何编辑 quicklisp 的系统定义文件

emacs - 在 LispBox 中的 Emacs 中加载 SLIME 编辑命令

string - Common Lisp 中字符串和数字的核心区别是什么?

prolog - 进入 SICStus Prolog 后?

php - PHP解析/语法错误;以及如何解决它们