[FIX] OrderedCollection
Stephan Rudlof
sr at evolgo.de
Sun May 21 01:24:54 UTC 2000
Bert Freudenberg wrote:
>
> On Fri, 19 May 2000, Stephan Rudlof wrote:
>
> > Bert Freudenberg wrote:
> >
> > > 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.
> >
> > I don't think, [...]
>
> You better should ;-)
>
> Please read again what I wrote, or just try the methods on
> OrderedCollections without my fixes.
I haven't tried them so far...
> You'll discover that an OC created
> with "new: size" still is empty
...wasn't aware of this point,...
> so that the "at:put:" will fail.
... and since I believe you, I don't have to try! ;-)
You have catched me: I had better tried this methods myself, before
'thinking' ;-(
Sorry!
> AFAICT
> this is not Squeak specific but the standard Smalltalk behaviour.
>
> -- Bert
Thank you.
But there remains the bug of
SequenceableCollection>>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 ArrayedCollections; evaluate:
#( 1 2 3) collect: [:e | e printString] from: 2 to: 3
, to generate an error (I have checked this! ;-) ).
I think this method could be fixed as
SequenceableCollection>>
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 - firstIndex +
1 put: (aBlock value: (self at: index))].
^ result
(checked, too).
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
|