[Pharo-project] Issue 3761 in pharo: overlappingPairsCollect: fails on OrderedCollections
Status: New Owner: ---- New issue 3761 by edoua...@gmail.com: 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'
Updates: Status: Accepted Comment #1 on issue 3761 by stephane...@gmail.com: overlappingPairsCollect: fails on OrderedCollections http://code.google.com/p/pharo/issues/detail?id=3761 (No comment was entered for this change.)
Comment #2 on issue 3761 by snoob...@yahoo.ie: 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
Comment #3 on issue 3761 by gazzagu...@googlemail.com: 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
Comment #4 on issue 3761 by ryd...@gmail.com: 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
Comment #5 on issue 3761 by edoua...@gmail.com: 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)) ] ]
Updates: Status: Fixed Labels: Milestone-1.3 Comment #6 on issue 3761 by stephane...@gmail.com: overlappingPairsCollect: fails on OrderedCollections http://code.google.com/p/pharo/issues/detail?id=3761 (No comment was entered for this change.)
Updates: Status: Closed Comment #7 on issue 3761 by stephane...@gmail.com: overlappingPairsCollect: fails on OrderedCollections http://code.google.com/p/pharo/issues/detail?id=3761 in 13067
participants (1)
-
pharo@googlecode.com