[BUG]Collection>>removeAll:

Andrew C. Greenberg werdna at mucow.com
Mon Aug 26 18:56:14 UTC 2002


Richard makes the untrue assumption that the only parameter aCollection 
that can give rise to this difficulty occurs when aCollection is an 
identity of self.  This is not the case.  The problems will occur, or 
similarly buggy problems will occur, WHENEVER a remove: of an element 
of the receiver will change the parameter.

There are many possible objects, some non-identical to self that could 
give rise to this problem.  Imagine a receiver collection corresponding 
to a sequentially indexable list of objects, and a parameter collection 
corresponding to a slice taken therefrom, such as the array and slice 
objects in Python.

There is no doubt that Richard handled a single case efficiently and 
elegantly.  But it is a single case.  And an undefined one.  No need to 
do this, because coders are supposed to understand that parameters to a 
collection iteration must be invariant.

Best that this be done without exception -- simply announcing that the 
result is undefined when the parameter is not invariant -- rather than 
simply adding a few "easy to evaluate" ad hoc cases, or to compromise 
system performance unnecessarily to satisfy Richard's sense of 
aesthetics.

After deep and due consideration, I am even more compelled after 
reading Richard's response than I was beforehand: Ralph and David are 
right and Richard is wrong on this point.

On Sunday, August 25, 2002, at 08:25 PM, Richard A. O'Keefe wrote:

> Why doesn't this take us into Halting Problem terrority?
>
> Because we simply are not talking about ALL functions, we are talking
> about ONE method, for which detecting the aliasing that is likely in
> practice is dead simple.
>
> As I have said before in other words, something like
>
>     removeAll: aCollection
>         self == aCollection ifTrue: [
> 	    self error: 'parameter aliased with receiver; stupid code'].
> 	^aCollection do: [:each | self remove: each]
>
> would not be as useful as a method that worked in all cases,
> but it _would_ be code that you could recommend with a straight face
> and a clear conscience.
>
> Whether it would be this easy in other cases is so far beyond the point
> that you couldn't see it with the Hubble telescope; it's this easy in
> THIS case.




More information about the Squeak-dev mailing list