2017-05-31 51 views
1

我收到以下錯誤試圖編譯一些代碼時:奇怪的錯誤編譯的Common Lisp代碼

Lambda list of method # is incompatible with that of the generic function INITIALIZE-INSTANCE. Method's lambda-list : (PAT::E) Generic-function's : (CCL::INSTANCE &REST CCL::INITARGS &KEY &ALLOW-OTHER-KEYS)

這裏是代碼導致錯誤:

(defclass event() 
    ((timestamp 
    :initarg :timestamp 
    :accessor timestamp) 
    (value 
    :initarg :value 
    :accessor value))) 

(defclass update (event) 
    ((security 
    :initarg :sectype 
    :accessor sectype))) 

(defclass prc (update) 
    ((lastp 
    :accessor lastp) 
    (lastv 
    :accessor lastv))) 

(defmethod initialize-instance :after ((e prc)) ; <- :(
    (setf (lastp e) (first (value e))) 
    (when (second (value e)) 
    (setf (lastv e) (second (value e))))) 

任何提示,以什麼可能造成錯誤將非常感激。

回答

4

您需要將參數列表末尾的&key添加到您的initialize-instance方法中。

從 「實用的Common Lisp」 章 「:17類對象的重新定位」:引用

The &key in the parameter list is required to keep the method's parameter list congruent with the generic function's--the parameter list specified for the INITIALIZE-INSTANCE generic function includes &key in order to allow individual methods to supply their own keyword parameters but doesn't require any particular ones. Thus, every method must specify &key even if it doesn't specify any &key parameters.