<div class="gmail_quote">On Sun, Mar 8, 2009 at 12:38 PM, Bert Freudenberg <span dir="ltr"><<a href="mailto:bert@freudenbergs.de">bert@freudenbergs.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
multiply := Array new: 4.<br>
1 to: 4 do: [:i |<br>
multiply at: i put: [:x | x * i].<br>
].<br>
<br>
And you would rightfully assume that this is equivalent to the version above, just more concise. But now try again:<br>
<br>
(multiply at: 3) value: 5.<br>
<br>
The answer will, surprisingly, not be 15 in current Squeak. </blockquote><div><br>You are right! 25, in fact...<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
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.</blockquote><div><br>So...VW does this "right," I guess, since I get 15 in VW NC 7.6? <br>
<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
So basically, you can use blocks as you always have, but they will behave as you might have assumed they would.<br><font color="#888888">
</font></blockquote></div><br>So the recent VM work discussed handles this? I will have to give that a try!<br><br>Thanks for the explanation! The next question, of course, is WHY does it get 25 and not 15... ;)<br><br>
Rob<br>