问题描述
我正在尝试创建一个可以在SBCL的插槽中存储符号向量的类.我不知道如何设置.
I'm trying to create a class that can store a vector of symbols in a slot in SBCL. I cannot figure out how to set it up.
到目前为止,我最好的猜测是
My best guess thus far has been
(defclass Individual ()
((discrete-decisions :type (vector symbol))))
这将返回以下错误:
keyword argument not a symbol:
(DISCRETE-DECISIONS :TYPE (VECTOR SYMBOL)).
[Condition of type SB-INT:SIMPLE-PROGRAM-ERROR]
一些实验表明,将类型更改为symbol
会返回相同的错误.我以为symbol
是Common Lisp中的有效类型...我误会了吗?
Some experimenting has shown that changing the type to just symbol
returns the same error. I thought that symbol
was a valid type in Common Lisp... am I mistaken?
如何使它正常工作?
上述问题我在Emacs 24.2下的2012年9月22日的Slime版本中运行了SBCL 1.0.58.当我从命令行运行SBCL 1.0.58时,没有问题.这似乎不是SBCL问题...
The above problem I had was running SBCL 1.0.58 in the 09-22-2012 Slime build under Emacs 24.2. When I run SBCL 1.0.58 from the command line, there is no problem. This doesn't seem like an SBCL issue...
推荐答案
您可以考虑在插槽访问器/写入器上定义:after方法.另外,可以通过定义自己的元类和自定义slot-value-using-class来行使最终的控制权
You might consider defining an :after method on slot accessor/writer. Also, the ultimate degree of control can be exercised by defining your own metaclass and customization of slot-value-using-class
这篇关于CLOS:如何使插槽具有强制的符号矢量类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!