[FIX] OrderedCollection
Stephan Rudlof
sr at evolgo.de
Fri May 19 21:45:20 UTC 2000
Bert Freudenberg wrote:
>
> On Thu, 18 May 2000, Stephan Rudlof wrote:
>
> > I think #collect:from:to: is a fix of a bug in the superclass version of
> > SequenceableCollection (think of starting collecting *not* with first
> > index).
> > Shouldn't it replace this method in SequenceableCollection instead of
> > overriding it?
> >
> > What was the problem for #withIndexCollect:?
>
> Both methods had the same problem. The SequenceableCollection
> implementation assumes that after "class new: size" it can use #at:put: to
> add elements. This is only true for ArrayedCollections, not for OCs. So
> you may be right and this might need to get fixed elsewhere.
>
> -- Bert
I don't think, that's the same problem for both methods.
The first one - in its original variant - has the problem of going out
of range, if the range doesn't start with 1; then the result is too
small to put something at lastIndex:
collect: aBlock from: firstIndex to: lastIndex
"Refer to the comment in Collection|collect:."
| result |
result _ self species new: lastIndex - firstIndex + 1.
firstIndex to: lastIndex do: [:index | result at: index put: (aBlock
value: (self at: index))].
^ result
For the second one >>withIndexCollect: I don't see this problem, because
it collects over the whole collection:
>From the class comment of SequenceableCollection:
---
I am an abstract superclass for collections that have a well-defined
order associated with their elements. Thus each element is
externally-named by integers referred to as indices.
---
And for its subclass OrderedCollection there exist >>at: and >>at:put:
(possibly this is Squeak specific?).
Greetings,
Stephan
--
Stephan Rudlof (sr at evolgo.de)
"Genius doesn't work on an assembly line basis.
You can't simply say, 'Today I will be brilliant.'"
-- Kirk, "The Ultimate Computer", stardate 4731.3
More information about the Squeak-dev
mailing list
|