This is the mail archive of the guile@cygnus.com mailing list for the guile project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
bothner@cygnus.com writes: > > However, it would please me (if it's not too deadly to implement) to > > see functions allowed to return set!-able references: > > > (set! (my-prop) 17) > > (my-prop) => 17 > > Kawa supports this (for some primitive functions - I haven't decided > yet how to define such functions in Scheme). > > Note that having functions "return set!-able references" is > probably not the way to do it, since we want a normal call (not in a > set! context) to return plain value, not a reference. Instead, > we allow functions to have "attributes", and one attribute is a > functions setter function. Then we define: > (set! (f . args) value) > as being syntactic sugar for: > ((setter f) value . args) > > > (While I'm at it, I'd argue for (set! (array-ref a 6) 'zork) etc. as a > > clean alternative to setf.) > > The advantage of this design is that it is procedural, while > setf is macro-based. Hence setf only works for setter functions > explicitly known (by name) at compile time, but setter works on > procedure *values* at run-time, and is therefore much more in > the spirit of Scheme. > I think this interface is a good thing. In fact, I wrote something similar for Guile purely in Scheme (it defined a new setf! syntactic form instead of overloading set!, but was based on a property of the procedure, not the symbol). I think the interface for setting the setter of an ordinary Scheme procedure should be: procedure: (set-setter! PROC SETTER-PROC) with `set-setter!' defined as the setter of `setter', so the user can do (purely for example purposes, this particular setter should be predefined): (set! (setter car) set-car!) Optionally, some syntactic sugar like define-with-setter might be useful. Is there any reason why that would be a bad interface? - Maciej