The standard does *not* support - a removeAll: a - [was: Re: [BUG] Collection>>removeAll:]

squeak-dev at lists.squeakfoundation.org squeak-dev at lists.squeakfoundation.org
Thu Sep 5 08:13:40 UTC 2002


"Lex Spoon" <lex at cc.gatech.edu> wrote:
> goran.hultgren at bluefish.se wrote:
> 
> > > Notwithstanding that, I am sensible to Richard's suggestion that when 
> > > it is practicable to catch a circumstance that misbehaves, we shouldn't 
> > > do so silently.  I am for adding the assert.
> > 
> > I can understand your points, but what about fixing the specific case by
> > calling removeAll instead?
> 
> This kind of silent fix can lead to trouble later when you make things
> slightly more complicated.  For example, suppose you looked at the
> following code, which worked:
> 
> 	a removeAll: a
> 
> and then changed it to this, which doesn't work:
> 
> 	a do: [ :each | a remove: each ]

Eh, the reason this doesn't work is that you are changing the collection
that you are iterating over.
That is, as has been established by many in these threads I think, your
problem as the writer of the code.
 
> It seems better to make it an error.  This situation is easily worked

Well, I know a few reasons for signalling an error instead of making it
work, but the above didn't sound like a good reason to me.

> around by using copies or by using removeAll.

Yes, I agree in this simple case. But what if the code is:

	a removAll: b  "or some other very complicated expression"

where b just happens to evaluate to a?

Anyway, do note that I am ok with just signalling as long as we still
add #removeAll.
I just want to hear the killer argument for not making it work. :-)

regards, Göran
 
> -Lex
> 
> 
> PS -- an alternative approach to this mess might be to mark a collection
> while it is being iterated, and for all modification commands to check
> whether the mark is turned on.



More information about the Squeak-dev mailing list