小编mon*_*712的帖子

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.

谢谢

lisp sbcl common-lisp clos

1
推荐指数
1
解决办法
228
查看次数

标签 统计

clos ×1

common-lisp ×1

lisp ×1

sbcl ×1