[comp.lang.lisp] SETF methods

ranson@cnetlu.UUCP (Ranson) (12/02/88)

The CLOS specification (88-002R) seems to assume that it is possible to
define SETF methods with:  (defun (setf foo) ...
I have never seen anything like that in the Steele book, and it does not
work with Allegro CL. Is it an extension being considered for ANSI Lisp?

     Daniel Ranson
     ...!mcvax!inria!cnetlu!ranson

ccm@a.gp.cs.cmu.edu (Christopher McConnell) (12/04/88)

The CLOS spec is specifying how to define setf methods (as in CLOS
methods with specializers) not the normal CL setf methods.  So, you
have to say (defmethod (setf woof) (value (object blah))).  You use
define-setf-method to define normal setf methods.
-- 

barmar@think.COM (Barry Margolin) (12/06/88)

In article <3761@pt.cs.cmu.edu> ccm@a.gp.cs.cmu.edu (Christopher McConnell) writes:
>The CLOS spec is specifying how to define setf methods (as in CLOS
>methods with specializers) not the normal CL setf methods.  So, you
>have to say (defmethod (setf woof) (value (object blah))).  You use
>define-setf-method to define normal setf methods.

No, that's not the answer.  The calling sequence for such a method
would be

	(setf <woof> <value> <blah>)

and that is not the normal SETF syntax.  CLOS needs a way for a class
to customize the behavior of

	(setf (<slot-name> <object>) <value>)

This is done by defining a method whose NAME is (setf <slot>), e.g.

	(defmethod (setf woof-frob) ((object woof) value)
	  "Set the FROB slot of a WOOF."
	  ...)

For this to fit in well with the rest of the system, general support
must be made for functions with names of the form (SETF <symbol>).
For instance, after doing the above DEFMETHOD, (function (setf
woof-frob)) should be valid.  Such general support has been proposed
within the ANSI committee (it has been bogged down for a while, mostly
because of a controversy over whether this is really needed, and if
so, whether SETF should be a special case or we should have a general,
extendable "function spec" facility (as several Lisp systems do)).

There are a couple of reasons why DEFINE-SETF-METHOD isn't good enough
for this feature.  The main problem is that we need names for these
functions, not just a way to define them and get them.  For example,
GENERIC-FLET and GENERIC-LABELS also need to be able to bind these
names.

Barry Margolin
Thinking Machines Corp.

barmar@think.com
{uunet,harvard}!think!barmar

ccm@a.gp.cs.cmu.edu (Christopher McConnell) (12/06/88)

I can only assume that you did not read my original post:

>The CLOS spec is specifying how to define setf methods (as in CLOS
>methods with specializers) not the normal CL setf methods.  So, you
>have to say (defmethod (setf woof) (value (object blah))).  You use
>define-setf-method to define normal setf methods.

I stand by it.  In the AAAI-88 copy of the CLOS specification:

(defmethod (SETF WOOF) (value (object blah))
  ...body)

is the defined way to define a setf method that is executed for 
(setf (woof object) value).  The parameter was moved to the begining
to allow &rest to capture a list of reference args.  You can also
write specializers for the value as well.

The comment about define-setf-method was meant to apply to the
question of how you would define a setf function for a NORMAL LISP
function, not a CLOS generic function.  (Since he was trying to use
DEFUN with the CLOS syntax, I assumed he was trying to apply the CLOS
syntax to the problem of a normal setf function.)

I agree that (function (SETF WOOF)) should return the setf function
and should be allowed in CL.
--