"Andy" == Andy Burnett andy.burnett@knowinnovation.com writes:
Andy> Randal said... Andy> <<With classic smalltalk 80 and Squeak:
Andy> a := (1 to: 10) do: [:n | [n]]. Andy> b := a collect: [:each | each value]. Andy> b will have something like #(10 10 10 10 ...).
Argh. That should have been collect: not do:
Andy> Out of curiosity I tried changing it to [:n | [n*10]], expecting the numbers Andy> to be ten times bigger, but they were stil 1, 2, 3... I also tried removing Andy> the whole block, and b still evaluated to the same values.
Works better with collect. :)
a := (1 to: 10) collect: [:n | [n * 10]]. b := a collect: [:each | each value]
b is now #(10 20 30 40 50 60 70 80 90 100) in a closure world. In non-closure, it would have been 100, 100, 100...