[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Problem with (setf dialog-item-text)
- Subject: Problem with (setf dialog-item-text)
- From: firstname.lastname@example.org (John R. Gersh)
- Date: Thu, 20 May 93 21:33:23 GMT
In article <199305201556.AA01913@imag.fr> Gilles Serasset writes:
>I am defining a view with an icon and a text. The size of the view depends
>on the text:
[Much Lisp code deleted]
>;;Everything works great, when I change the dialog-item-text, the size is
>;;recalculated and the dialog-item is redisplayed properly.
>;;Then, I define the method for (setf dialog-item-text):
>(defmethod (setf dialog-item-text) ((self icon-and-text-dialog-item) text)
> (set-dialog-item-text self text))
>;;It does not work, the text is change, but the size is not recalculated and the
>;;icon not redisplayed. WHY ????????
This is a subtle one. CLtL2, section 22.214.171.124 (p. 777), says that the
generic function for writing into a slot "takes two arguments: the new
value and the instance, in that order." If an accessor (rather than a
writer) is defined, the name of the generic function is "(setf
<slot-name>)" rather than "<slot-name>," but, presumably, the order of
its arguments is the same.
The definition above for (setf dialog-item-text) has arguments in the
order: instance, new-value, with the _first_ argument specialized on
the icon-and-text-dialog-item class. It does not agree, therefore,
with the method for (setf dialog-item-text) constructed by the
defclass for dialog-item, and inherited by icon-and-text-dialog-item,
which specializes the its _second_ argument on the class.
The defmethod above, therefore, does not replace the existing one in
the generic function (setf dialog-item-text), it adds one with
different argument specialization. [CLtL2 p.789] Consequently when the
(setf (dialog-item-text di) "Salut")
it's the original method that's called, one that just sets the slot's
If the method above is defined
(defmethod (setf dialog-item-text) (text (self icon-and-text-dialog-item))
(set-dialog-item-text self text))
then things seem to work as desired.
John Gersh John_Gersh@jhuapl.edu
The Johns Hopkins University Applied Physics Laboratory
Johns Hopkins Rd., Laurel, MD 20723 (301) 953-5503