Issue 3761 in pharo: overlappingPairsCollect: fails on OrderedCollections

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Issue 3761 in pharo: overlappingPairsCollect: fails on OrderedCollections

pharo
Status: New
Owner: ----

New issue 3761 by [hidden email]: overlappingPairsCollect: fails on  
OrderedCollections
http://code.google.com/p/pharo/issues/detail?id=3761

Pharo image: Pharo
Pharo core version: Pharo1.2rc2 #12336
Virtual machine used: (one-click image with cog)

Steps to reproduce:

collection := OrderedCollection withAll: #(1 2 3 4 5).
collection overlappingPairsCollect: [ :a :b | a + b ].

raises exception: 'attempt to index non-existent element in an ordered  
collection'



Reply | Threaded
Open this post in threaded view
|

Re: Issue 3761 in pharo: overlappingPairsCollect: fails on OrderedCollections

pharo
Updates:
        Status: Accepted

Comment #1 on issue 3761 by [hidden email]: overlappingPairsCollect:  
fails on OrderedCollections
http://code.google.com/p/pharo/issues/detail?id=3761

(No comment was entered for this change.)


Reply | Threaded
Open this post in threaded view
|

Re: Issue 3761 in pharo: overlappingPairsCollect: fails on OrderedCollections

pharo

Comment #2 on issue 3761 by [hidden email]: overlappingPairsCollect:  
fails on OrderedCollections
http://code.google.com/p/pharo/issues/detail?id=3761

Need to change #at:put: to rather be #add:.

The reason for this is explained in comment of OrderedCollection>>at:put:
"Put anObject at element index anInteger. at:put: cannot be used to append,  
front or back, to an ordered collection; it is used by a knowledgeable  
client to replace an element."

Change could be as given below...

overlappingPairsCollect: aBlock
        "Answer the result of evaluating aBlock with all of the overlapping pairs  
of my elements."
        | retval |
        retval := self species new: self size - 1.
        1 to: self size - 1
                do: [:i | retval add: (aBlock value: (self at: i) value: (self at: i +  
1)) ].
        ^retval


Reply | Threaded
Open this post in threaded view
|

Re: Issue 3761 in pharo: overlappingPairsCollect: fails on OrderedCollections

pharo

Comment #3 on issue 3761 by [hidden email]:  
overlappingPairsCollect: fails on OrderedCollections
http://code.google.com/p/pharo/issues/detail?id=3761

Except that it would then fail if the receiver was an Array, for instance.
The following should work though:


overlappingPairsCollect: aBlock
        "Answer the result of evaluating aBlock with all of the overlapping pairs  
of my elements."
        | retval |
        retval := self species ofSize: self size - 1.
        1 to: self size - 1
                do: [:i | retval at: i put: (aBlock value: (self at: i) value: (self at:  
i + 1)) ].
        ^retval




Reply | Threaded
Open this post in threaded view
|

Re: Issue 3761 in pharo: overlappingPairsCollect: fails on OrderedCollections

pharo

Comment #4 on issue 3761 by [hidden email]: overlappingPairsCollect:  
fails on OrderedCollections
http://code.google.com/p/pharo/issues/detail?id=3761

Yup, that is the same fix as was implemented in squeak:
http://forum.world.st/The-Trunk-Collections-ul-430-mcz-td3329332.html


Reply | Threaded
Open this post in threaded view
|

Re: Issue 3761 in pharo: overlappingPairsCollect: fails on OrderedCollections

pharo

Comment #5 on issue 3761 by [hidden email]: overlappingPairsCollect:  
fails on OrderedCollections
http://code.google.com/p/pharo/issues/detail?id=3761

Is #streamContents: better, or are there performance implications?

overlappingPairsCollect: aBlock

        "Answer the result of evaluating aBlock with all of the overlapping pairs  
of my elements."

        ^ self species streamContents: [ :stream |
                1 to: self size - 1
                        do: [ :i | stream nextPut: (aBlock value: (self at: i) value: (self at:  
i + 1)) ]
                ]


Reply | Threaded
Open this post in threaded view
|

Re: Issue 3761 in pharo: overlappingPairsCollect: fails on OrderedCollections

pharo
Updates:
        Status: Fixed
        Labels: Milestone-1.3

Comment #6 on issue 3761 by [hidden email]: overlappingPairsCollect:  
fails on OrderedCollections
http://code.google.com/p/pharo/issues/detail?id=3761

(No comment was entered for this change.)


Reply | Threaded
Open this post in threaded view
|

Re: Issue 3761 in pharo: overlappingPairsCollect: fails on OrderedCollections

pharo
Updates:
        Status: Closed

Comment #7 on issue 3761 by [hidden email]: overlappingPairsCollect:  
fails on OrderedCollections
http://code.google.com/p/pharo/issues/detail?id=3761

in 13067