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

with-slots and specialized

REGARDING                with-slots and specialized setf's
If  the value of a slot is set from within a call to with-slots, before and
after methods on setf are ignored. This is not the case when the call is from
within with-accessors. 
This is very counter-intuitive. But is it a bug? CLtL didn't help me very much.


(defclass test-item ()
   (test-slot :initarg :test-slot :initform nil :accessor test-slot

(defmethod (setf test-slot) :before (to (item test-item))
  (format t "~%value of test-slot of object ~a is now ~a" item to))

(defmethod set-test-slot1 ((item test-item) value)
  (with-slots (test-slot) item
    (setf test-slot value)))

(defmethod set-test-slot2 ((item test-item) value)
  (with-accessors ((the-slot test-slot)) item
    (setf the-slot value)))

(setf (test-slot (make-instance 'test-item)) 10)

(set-test-slot1 (make-instance 'test-item) 10)

(set-test-slot2 (make-instance 'test-item) 10)

Any ideas? Thanks,

Andre Koehorst
email: andre@riks.nl
Research Institute for Knowledge Based Systems
Maastricht, The Netherlands.