Randal said...<br>
<br>
&lt;&lt;With classic smalltalk 80 and Squeak:<br>

<br>a := (1 to: 10) do: [:n | [n]].<br>
b := a collect: [:each | each value].<br>

b will have something like #(10 10 10 10 ...).<br>

<br>The problem is that the :n in each block ([n]) is shared as one variable.<br>

In a true closure, which modern Squeak and Pharo provide, we get the proper<br>
#(1 2 3 4 ... 10).  That&#39;s because each apperance of &quot;n&quot; is &quot;closed&quot; with<br>
respect to the newly created block.&gt;&gt;<br><br>Thanks for explaining the difference between blocks and closures. I think I new understand that.  And, your example raised a new question for me.<br><br>What does the inner &#39;block&#39; in [:n | [n]] actually do? <br>
<br>Out of curiosity I tried changing it to [:n | [n*10]], expecting the numbers to be ten times bigger, but they were stil 1, 2, 3...  I also tried removing the whole block, and b still evaluated to the same values.<br><br>
Cheers<br>Andy<br>