Couple of years ago, I found a code snippet on the Squeak Mailing list that presented kind of worst case scenario for ST block closures.
| blockArray dataArray |
blockArray := Array new: 5.
dataArray := #( 'Apple' 'Orange' 'Grape' 'Lemon' 'Kiwi').
1 to: blockArray size do: [ :index |
blockArray
at: index
put: [ dataArray at: index ] ].
^ (blockArray at: 2) value
The results of the various ST VM's were given as:
Dolphin : Subscript out of bounds error (Array>>at:)
Smalltalk Express : primitive fails in Arrat>>at:VSE 3.1 : anwers 'Orange'
VisualWorks 2.5.1 : answers 'Orange'
VisualWorks Non-Commercial 3.0 : answers 'Orange'
VisualWorks Beta 5i : raises a SubscriptOutOfBoundsSignal in Core::Array>>at:
VisualAge for Smalltalk 4.5 : answers 'Kiwi'
I would think that the answer should be Orange, as the value of the index at each code block is latched at the time it is created. Guess I need to try it on this version of Squeak, as it errored out on the earlier versions of Squeak that didn't have closures. :-)
|