Arguments to :writer function in slot definitions. 
Author Message
 Arguments to :writer function in slot definitions.

Hello,

this is one thing it has been nagging me for quite some time now.

The Hyperspec does not help.

It seems like that when defining (at least in CMUCL)

(defclass zz ()
  ((slot :writer set-slot))    ; Write-only memory!!!! :)
  )

the signature of the writer gf method is

  (defmethod set-slot (value (z zz)) #|do the (setf (slot-value ..)) |#)

which results into calls of the form

  (set-slot the-value the-zz)

Now, I could not really find in the Hyperspec the definition of the
arg list for the writer gf.  But I am curious to know what is the
rationale for this choice, beyond the fact that you can write things
like

  ((slot :writer (setf slot)))

..and that some of the SETF-related functions seem to like the "value"
argument in the first position of the arglist.

Just curious.

Cheers

--
Marco Antoniotti ===========================================
PARADES, Via San Pantaleo 66, I-00186 Rome, ITALY
tel. +39 - 06 68 10 03 17, fax. +39 - 06 68 80 79 26
http://www.*-*-*.com/ ~marcoxa



Sat, 13 Oct 2001 03:00:00 GMT  
 Arguments to :writer function in slot definitions.

Quote:

>   (set-slot the-value the-zz)

> Now, I could not really find in the Hyperspec the definition of the
> arg list for the writer gf.  But I am curious to know what is the
> rationale for this choice, beyond the fact that you can write things
> like

>   ((slot :writer (setf slot)))

> ..and that some of the SETF-related functions seem to like the "value"
> argument in the first position of the arglist.

The reason that SETF takes new-value first is because you can't add an
argument at the end after options and rest.  That is, for a function
with arglist (x &rest y), the setter can't be (x &rest y new-value)
so the head of the list is the only place you can put it where you can
mechanically create a new and coherent and predictable arglist.

Why the writer takes its arguments in that order is a mystery to me
these days though something tells me there was a reason.
My recollection was that New Flavors did it the other way.
(New Flavors is distinguished from Old Flavors by the replacement of
SEND with generic functions, among other things, so it had a similar
set of issues.)  So whatever we did was, I'm pretty sure, going against
the grain of current practice, and I *suspect* the issue was that
people had an awful time remembering if new-value came first or last,
and that we just wanted a single language-wide rule so that people
didn't misremember.  Remember that if you have
 (SET-FRIEND fred sally)
you might have a problem that you can't detect the args are in the
wrong order, so it's very hard to signal a compiler diagnostic if the
user has gotten confused.  Painful as it may be to remember that new-value
goes first, at least you don't have to remember that it sometimes goes
first and have to learn where it does and where it doesn't.

So I doubt it's the :writer (setf slot) thing you're saying, although
that's a direct consequence of this other issue.

But I'm mostly just guessing on this, based on other facts I remember
more clearly and based on the general kinds of reasoning we typically
did.  My specific memory on this is not very good, so please attach to
any of the above with appropriately weak pointers.



Sat, 13 Oct 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Slots of a slot definition metaobject

2. Stump on MOP in re Slot definition

3. computed types vs. slot definitions

4. Multiple arguments, structured arguments [ LONG ] (was Re: dyadic functions)

5. passing functions with variable number of arguments as procedure arguments

6. Functions attributes accessed from within the function definition URGENT please

7. F77-C: Passing Fortran FUNCTION as an argument for a C Function

8. Passing array valued functions as argument to function.

9. Intrinsoc function as argument to intrinsic function question

10. F95: array-returning function as argument to another function

11. tcl+C function with pointer function argument?

12. Yet another INTERFACE and functional argument definition

 

 
Powered by phpBB® Forum Software