Hello list:
I've seen some messages talking about incorporating closure support into Squeak/Pharo.
What does this mean? A closure is a block, right? And Squeak has already blocks...
Thanks in advance!
"Alex" == Alex Schenkman alex@schenkman.info writes:
Alex> What does this mean? Alex> A closure is a block, right? And Squeak has already blocks...
A closure is a block but not all blocks are closures.
With classic smalltalk 80 and Squeak:
a := (1 to: 10) do: [:n | [n]]. b := a collect: [:each | each value].
b will have something like #(10 10 10 10 ...).
The problem is that the :n in each block ([n]) is shared as one variable.
In a true closure, which modern Squeak and Pharo provide, we get the proper #(1 2 3 4 ... 10). That's because each apperance of "n" is "closed" with respect to the newly created block.
beginners@lists.squeakfoundation.org