[squeak-dev] Variable capture in block closure

Bob Arning arning315 at comcast.net
Mon Jan 21 18:01:18 UTC 2019


just curious - which of those surprises you?

On 1/21/19 12:47 PM, Stéphane Rollandin wrote:
> 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
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20190121/dbc6dcd3/attachment.html>


More information about the Squeak-dev mailing list