mon*_*712 1 lisp sbcl common-lisp clos
当类在列表中时,我无法使用clos访问器函数.
说我上课了:
(defclass a ()
((a :accessor a
:initarg :a)))
Run Code Online (Sandbox Code Playgroud)
我做了2个实例:
(defparameter b (make-instance 'a :a 1))
(defparameter c (make-instance 'a :a 2))
Run Code Online (Sandbox Code Playgroud)
然后如果我想创建一个函数来获取每个实例的值,而在列表中我会这样做
(defun get-a (lst)
(mapcar #'a lst))
Run Code Online (Sandbox Code Playgroud)
并称之为
(get-a '(b c))
Run Code Online (Sandbox Code Playgroud)
但我这样做我得到一个错误:
There is no applicable method for the generic function
#<STANDARD-GENERIC-FUNCTION A (1)>
when called with arguments
(B).
[Condition of type SIMPLE-ERROR]
Run Code Online (Sandbox Code Playgroud)
如果不是直接用mapcar调用访问器,我也会调用包含访问器的函数.我也尝试过使用循环和其他东西而不是mapcar.
谢谢
如果您阅读了错误,则会得到解释.
There is no applicable method for the generic function
#<STANDARD-GENERIC-FUNCTION A (1)>
when called with arguments
(B).
Run Code Online (Sandbox Code Playgroud)
所以你接到一个电话,类似于(a 'b).但它b是一个符号,而不是一个CLOS实例.
(b c)是两个符号的列表.您可能想要创建两个CLOS实例的列表.使用LIST创建与评估参数列表.