[comp.lang.clos] Defining SETF :AFTER methods in PCL

rodney@huntsai.boeing.com (Rodney Daughtrey) (01/18/91)

Consider the following code:



(defclass foo ()
  ((bar :type string
        :accessor foo-bar)))


(defmethod (setf foo-bar) :after ((self foo) value)
  (format t "~%FOO-BAR is now ~A" value))


(let ((foo-1 (make-instance 'foo)))
  (setf (foo-bar foo-1) "Hello"))



When I evaluate this code, I expected to see

FOO-BAR is now HELLO
"Hello"

but all I got was

"Hello"


What am I doing wrong?  Is there a better way to accomplish this?
I'm using PCL on the Macintosh using Allegro Common LISP 1.3.2.
Thanks!



Rodney Daughtrey           E-mail: rodney@huntsai.boeing.com
Huntsville AI Center               {major site}!uw-beaver!bcsaic!huntsai!rodney
Boeing Computer Services   Voice:  (205)-461-2352  Fax: (205)-461-2933

desrivieres.parc@XEROX.COM (Jim des Rivieres) (01/18/91)

Counterintuitively, all (setf xxx) functions and methods take the new value as
their *first* argument; i.e., try

(defmethod (setf foo-bar) :after (value (self foo))
  (format t "~%FOO-BAR is now ~A" value))

john@mingus.mitre.org (John D. Burger) (01/19/91)

desrivieres.parc@XEROX.COM (Jim des Rivieres) writes:

> Counterintuitively, all (setf xxx) functions and methods take the new
> value as their *first* argument;

What other argument position makes sense?  If you make it the last
argument of the SETF function/method, you can't have optional, rest or
keyword arguments.

John Burger



--
John Burger                                               john@mitre.org

"You ever think about .signature files? I mean, do we really need them?"
  - alt.andy.rooney