[squeak-dev] Variable capture in block closure

Stéphane Rollandin lecteur at zogotounga.net
Mon Jan 21 17:47:58 UTC 2019


Hello all,

Is it expected that

	| blocks x |

	blocks := OrderedCollection new.

	(1 to: 3) do: [:n |
		x := n.
		blocks add: [Transcript showln: x]].

	blocks do: #value


prints 3 three times, while

	| blocks |

	blocks := OrderedCollection new.

	(1 to: 3) do: [:n |
		| x |
		x := n.
		blocks add: [Transcript showln: x]].

	blocks do: #value

prints 1, 2, 3 ?

Stef


More information about the Squeak-dev mailing list