[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: How can I change the arguments of a generic function in MCL?



>I came across the message "Error: Incompatible lambda list" when I
>tried to define an :after method and add a new keyword argument there. 
>Original lambda list has not any keyword argument.

>Any suggestion would be appreciated.

>>You need to redefine the generic function using DEFGENERIC if you want
>>to change its argument list.  Once you do that you will then need to
>>make the corresponding change to the argument list of every method and
>>recompile them.  This is true of every CLOS implementation.

If some of the methods of the generic function are defined as accessors via
defclass, you will need to define them explicitly instead with your desired
lambda list.

For Example:

Welcome to Macintosh Common Lisp Version 2.0!
? (defclass c1 () ((s1 :reader s1 :initform nil)))
#<STANDARD-CLASS C1>
? (defmethod (setf s1) ((value t) (c1 c1) &key)
   (setf (slot-value c1 's1) value))
#<STANDARD-METHOD (SETF S1) (T C1)>
? (defmethod (setf s1) :after ((value t) (c1 c1) &key print-foo)
     (if print-foo (print 'foo)))
#<STANDARD-METHOD (SETF S1) :AFTER (T C1)>
? (defvar *i1*)
*I1*
? (setf *i1* (make-instance 'c1))
#<C1 #x457359>
? (setf (s1 *i1*) 'bar)
BAR
? (setf (s1 *i1* :print-foo t) 'baz)

FOO 
BAZ
?