[BUG]Collection>>removeAll:

Norton, Chris chrisn at Kronos.com
Tue Aug 20 15:19:19 UTC 2002


Richard A. O'Keefe wrote:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The question is, what is the important thing about the result of
#removeAll:?

If it is the IDENTITY of aCollection, then Chris Norton's code (which
differs from mine only in returning aCollection) is the right way to go.

If it is the CONTENTS of aCollection, then my code (which differs from Chris
Norton's only in returning itemsToRemove) is the right way to go.

I have real trouble believing that the identity is all-important.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You will not find an argument with me, Richard; your experience in computing
far outshines mine.

However, I will point out that the original comment, which I pasted into my
version of the method, indicated that the returned collection should be the
collection that was used as the argument to #removeAll:.  I too was confused
by this, so I looked at the implementation of #removeAll: in VA Smalltalk
and in VisualSmalltalk Enterprise -- all of these Smalltalks do the same
thing -- they return the collection that was passed in.

VA:

Collection>>removeAll: aCollection
	"For each element in aCollection, remove the first element from the
receiver
	 which is equal to this element."

	^aCollection do: [:element | self remove: element]

VSE:

Collection>>removeAll: aCollection
    "Answer aCollection.  Remove all the elements
     contained in aCollection from the receiver collection."

    aCollection do: [:element | self remove: element].
    ^aCollection

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

After my investigation was complete, I sent that reply with my small code
change to y'all.  I don't know the history of this method (Collection has
been around a long time), but I suspect that it was designed to work this
way.

What do you ANSI Smalltalk people think about this issue?  Has this been
wrong since the dawn of Smalltalk?

Cheers,

---==> Chris



More information about the Squeak-dev mailing list