2014-03-05 47 views
1

當類在列表中時,我無法使用clos訪問器函數。lisp clos訪問器問題

說我有類:

(defclass a() 
    ((a :accessor a 
     :initarg :a))) 

我做2個實例:

(defparameter b (make-instance 'a :a 1)) 
(defparameter c (make-instance 'a :a 2)) 

,然後,如果我想創造會得到一個值,爲每個實例的功能而列表中的我會做

(defun get-a (lst) 
    (mapcar #'a lst)) 

叫它
(get-a '(b c)) 

,但我這樣做,我得到一個錯誤:

There is no applicable method for the generic function 
    #<STANDARD-GENERIC-FUNCTION A (1)> 
when called with arguments 
    (B). 
    [Condition of type SIMPLE-ERROR] 

而且它也恰好的,如果不是直接與mapcar調用訪問,我把它包含存取的功能。此外,我嘗試使用循環和其他東西,而不是mapcar。

謝謝

+0

'(get-a(list b c))',而不是'(get-a'(b c))'。 –

回答

5

如果您閱讀錯誤,您會得到解釋。

There is no applicable method for the generic function 
    #<STANDARD-GENERIC-FUNCTION A (1)> 
when called with arguments 
    (B). 

所以你接到了一個電話,這與(a 'b)類似。但b是一個符號,而不是CLOS實例。

(b c)是兩個符號的列表。您可能想要創建兩個CLOS實例的列表。使用LIST創建一個包含評估參數的列表。

+0

修復它,謝謝 – mondoman712