[Prev][Next][Index][Thread]
Re: A Proposal!!
Why not say that all !'ed versions _must_ maintain eq?-ness and all
non-!'ed versions _never_ side-effect the existing object?
Calling xxx! on non-mutable objects, such as a <range>, would give an
error.
This is a major change to the collection operations, but, IMO, a good
one.
>>>>> "Jon" == Jon Hewitt <hewittj1752@my-deja.com> writes:
Jon> Hi,
Jon> One of the gotchas that has bothered me about Dylan is add!(). In
Jon> particular I based my code on the Harlequin's Task List Manager example,
Jon> it compiled but it didn't work. The problem turned out to be that I was
Jon> using the <list> class for my collection class instead of the
Jon> <stretchy-vector> class that the example used. Thus since the result of
Jon> add!(<list>, <object>) is not necessarily == to the passed in <list>,
Jon> one must utilize the result. The Task List Manager code uses an
Jon> optimization: since the result is guaranteed to be == the supplied
Jon> <stretchy-vector> it could skip assigning the result to a local
Jon> variable.
Jon> So I have come to believe that the versions of add!() that maintain
Jon> identity should be treated as a separate method from the versions that
Jon> don't maintain identity. So I would like to propose a new convention.
Jon> First always utilize the result of a destructive operation that has a
Jon> '!' suffix. Second, if a destructive operation maintains the identity
Jon> of its input, provide a second version of the method that returns no
Jon> result and has a '!!' suffix. Thus one can choose between greater
Jon> portability, add!(), or greater optimization, add!!(). Hopefully the
Jon> following example will clarify my proposal:
--
Greg gregs@ai.mit.edu (617)253-5807
Sullivan http://www.ai.mit.edu/~gregs/
Follow-Ups:
References: