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

Eliot Miranda eliot.miranda at gmail.com
Mon Mar 9 02:11:11 UTC 2009


Hi Rob,

On Sun, Mar 8, 2009 at 10:13 AM, Rob Rothwell <r.j.rothwell at gmail.com>wrote:

> 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... ;)


My blog goes into the excruciating details:

    http://www.mirandabanda.org/cogblog/2008/06/07/closures-part-i/

and the other posts starting with "Closures"

HTH

Eliot.

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


More information about the Squeak-dev mailing list