2015-03-18 22:55 GMT+01:00 Sean P. DeNigris <sean@clipperadams.com>:
e.g. someObject mongoDo: [ ... ].
withIndexDo: obeys the principle of least astonishment to me.
Except the difference between this case and the other examples is that "withIndex + Do:" reverses the argument order (:e :i).
No, the argument order is perfectly right :) aCollection withIndexDo: == "for each collection element 'e' with index 'i' do: [:e :i | ....]"
But more importantly, GNU and other Smalltalks have #doWithIndex:. I donât think that the payoff here is enough to diverge from the rest of the world.
Lastly, apparently e.g. Dolphin has removed it completely in favor of #keysAndValuesDo: in response to a change in the ANSI standard. From http://forum.world.st/doWithIndex-tp3374968p3374975.html :
#doWithIndex: was in an early ANSI draft, presumably proposed by one of IBM's representatives but I can't really remember, and we had it in the version of Dolphin current at the time. Later it was removed from the standard and replaced with #keysAndValuesDo:, which makes sense since a sequenced collection can legimitately represent a "keyed collection" with integer keys. Therefore there is no need for a second enumerator that does the same thing but with key and value reversed.
Cheers, Sean
------------------------------ View this message in context: Re: when iterating over a collection how to determine the current objects index <http://forum.world.st/when-iterating-over-a-collection-how-to-determine-the-...> Sent from the Pharo Smalltalk Users mailing list archive <http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html> at Nabble.com.