[squeak-dev] Re: New Window VM (Closures, FT2Plugin, Large Cursors)

Rob Rothwell r.j.rothwell at gmail.com
Sun Mar 8 17:13:51 UTC 2009


On Sun, Mar 8, 2009 at 12:38 PM, Bert Freudenberg <bert at freudenbergs.de>wrote:

> multiply := Array new: 4.
> 1 to: 4 do: [:i |
>        multiply at: i put: [:x | x * i].
> ].
>
> And you would rightfully assume that this is equivalent to the version
> above, just more concise. But now try again:
>
> (multiply at: 3) value: 5.
>
> The answer will, surprisingly, not be 15 in current Squeak.


You are right!  25, in fact...


> But with closures, the blocks would behave as expected. They are said to
> "close over" the state that the bound variables (i in this case) had at the
> time the block was created.


So...VW does this "right," I guess, since I get 15 in VW NC 7.6?

So basically, you can use blocks as you always have, but they will behave as
> you might have assumed they would.
>

So the recent VM work discussed handles this?  I will have to give that a
try!

Thanks for the explanation!  The next question, of course, is WHY does it
get 25 and not 15... ;)

Rob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20090308/ca7eaf41/attachment.htm


More information about the Squeak-dev mailing list