[comp.lang.clos] Defining SETF methods for CLOS methods

mdb@arcsun.arc.ab.ca (Mark Brinsmead) (12/06/90)

   I have a (slightly) new question, which I think relates to the discussion
of naming conventions in CLOS:

   What is the "officially sanctioned" way of defining a setf method for ONE 
SPECIFIC method of a generic function?  My reading of the standards
implies that
something of the form:

   (defsetf (find-method <generic-function> (<specializers>)) ...)

ought to do it, but the version of PCL I am using (which I thought to be the
most recent!) does not seem to support FIND-METHOD, so I can't experiment.

   What I am trying to do (though its of little relevance) is to define a
write-once slot.  Defining it with a :ACCESSOR makes the slot just plain
writable; I want to allow writing ONLY as long as the slot-value is the
default, in this case, NIL.

--  Mark Brinsmead,		(mdb@arcsun.arc.ab.ca)
    Alberta Research Council

barmar@think.com (Barry Margolin) (12/06/90)

In article <1990Dec5.212406.20667@arc.ab.ca> mdb@arcsun.arc.ab.ca (Mark Brinsmead) writes:
>   What is the "officially sanctioned" way of defining a setf method for ONE 
>SPECIFIC method of a generic function?  My reading of the standards
>implies that
>something of the form:
>
>   (defsetf (find-method <generic-function> (<specializers>)) ...)
>
>ought to do it, but the version of PCL I am using (which I thought to be the
>most recent!) does not seem to support FIND-METHOD, so I can't experiment.

I don't know where you could have read that.  DEFSETF doesn't evaluate its
arguments, so it doesn't matter whether FIND-METHOD is defined; the first
argument to DEFSETF is required to be a symbol.

The correct way to define a CLOS SETF function is:

(defmethod (setf <slot-name>) <qualifiers> (<specializers>) ...)

>   What I am trying to do (though its of little relevance) is to define a
>write-once slot.  Defining it with a :ACCESSOR makes the slot just plain
>writable; I want to allow writing ONLY as long as the slot-value is the
>default, in this case, NIL.

You might want to do this using a BEFORE or AROUND method, so that the
default primary method will continue to fill in the slot using the default
mechanism.  A BEFORE method could be used if you want an error to be
signalled if an attempt is made to assign the slot twice; an AROUND method
could be more flexible (e.g. just ignore the attempt to reassign, by not
calling NEXT-METHOD).
--
Barry Margolin, Thinking Machines Corp.

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