[CM] A question of methods

Rick Taube taube@uiuc.edu
Fri, 27 Sep 2002 05:23:57 -0500

if you use accessors instead of slot-value then its possible to write an :after method for the class that does what you want, ie something like: 

(defclass cue ((goals :accessor cue-goals)))

(defmethod (setf cue-goals) :after ((obj cue) val)
  (setf (slot-value obj 'goals)
	(frob-list (slot-value obj 'goals))))

>I have an object (let's call it a cue)  with a slot that is a list of
>times (let's call the slot goals), I wish to ensure, any time that the
>slot value of goals is changed in any cue, that the resulting list is
>in chronological order.
>So, for example:
>(setf my-cue (make-instance 'cue :goals '(1 2 3 4)))
>(slot-value my-cue 'goals)
>-> (1 2 3 4)