gen :=
[
[ | currentValue |
Array
with: [ currentValue := 0 ]
with: [ currentValue := currentValue + 1 ]
] value
] value.
gen first value.
next := [:a | a last value].
getTen := [(1 to: 10) collect: [ :i | next value: gen ]].
getTen value = #
(1 2 3 4 5 6 7 8 9 10).
getTen value = #(11 12 13 14 15 16 17 18 19 20).
There have been some funny arguments in the past whether Blocks are a fundamental part of Smalltalk or not. My code above supports Vassili's view that we could get rid of Objects and implement everything in terms of Blocks.