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] |
Maciej Stachowiak <mstachow@MIT.EDU> writes: > mdj@nada.kth.se writes: [...] > > 4. Assume that G is an instance of <getter-with-setter>. > > Then G has the following properties: > > a) G has no slots > > b) There exists no mutator which can alter G. > > c) G =/= (getter G) > > d) (G A1 ...) <=> ((getter G) A1 ...) > > e) (set! (G A1 ...) V) <=> ((setter G) V A1 ...) [...] > > 6. (define-metod (add-method! ((g <getter-with-setter>) (m <method>))) > > (add-method! (getter g) m)) > ^^^^^^ > > Why is this necessary? WOuldn't applying a getter-with-setter apply > the getter anyway and therefore have the correct semantics? It's because the default `add-method!' needs a <generic> as its first argument. While `g' above is a <getter-with-setter>, (getter g) is a <generic> (hopefully!). [...] > That's the solution I was going to suggest, allong with the following > convenience macro (which would be useful more generally): > > (defmacro define-setter (name setter) > (let ((old-name (gensym))) > `(let ((,old-name ,name)) > (set! ,name (make-getter-with-setter > (if (getter-with-setter? ,name) > (getter ,name) > ,name) > ,setter))))) Good idea. [...] > A smarter > `define-setter' could work more like define [allowing, e.g. > > (define-setter (getter-name arg1 arg2 arg3 value) > (some code)) > > ] but this may be confusing. Why? > > 8. He can add new methods to the setter with > > > > (add-method! (setter G) M) > > > > I am pretty sure this would work without the need for point 6, and > while making use of my above suggestion. I don't understand. Could you explain it a bit further? > Noting my above suggestion, it would even be possibly to have > `define-setter-method' automatically create a setter generic for the > generic by doing a trick like `define-setter' if it is not already a > `setter-with-getter'. Yes. > So you'd copy the innards of the closure when you call > `make-getter-with-setter'? For correct semantics they would have to > share code and environments.... Why? The semantics will also be correct if the <getter-with-setter> closure calls the getter. (As an optimization, though, the code and environment pointers will be copied from the getter if the getter is a closure.) > I still think it should be called a <procedure-with-setter> (`getter' > could be interpreted as possibly referring to a macro) but I don't > care too much. I think I like the name <procedure-with-setter> as well, but you still haven't given me any arguments! :) /mdj