<div dir="ltr"><br><br><div class="gmail_quote">On Thu, Jul 31, 2008 at 3:54 PM, Ramon Leon <span dir="ltr"><<a href="mailto:ramon.leon@allresnet.com">ramon.leon@allresnet.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="Wj3C7c"><br>
> askoh wrote:<br>
> > | block |<br>
> > block := [:i | Transcript cr; show: i].<br>
> > 1 to: 10 do: [:i | block value: i+1]<br>
> ><br>
> > The above should print ten times. But it only prints the<br>
> five even numbers.<br>
> > That is a bug isn't it?<br>
> ><br>
> > Aik-Siong Koh<br>
> ><br>
> More of a "known limitation" than a bug... due to the fact<br>
> that squeak<br>
> does not have proper closures.<br>
><br>
> try<br>
><br>
> | block |<br>
> block := [:j | Transcript cr; show: j].<br>
> 1 to: 10 do: [:i | block value: i+1]<br>
><br>
> Keith<br>
<br>
</div></div>I was going to say that, but why does it work using (1 to: 10) do: rather<br>
than 1 to: 10 do:, seems related to #to:do: being inlined?</blockquote><div><br></div><div>Yes. In the activation of to:do: there is a different counter. Look at the implementation of Number>>to:do:. So while both i's are still the same lvalue, i is not used by Number>>to:do: either to control the loop iterations or to to derive the values for the loop. Only when the loop is inlined does i become the loop control variable.</div>
<div><br></div><div>HTH</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div class="Wj3C7c">Ramon Leon<br>
<a href="http://onsmalltalk.com" target="_blank">http://onsmalltalk.com</a><br>
<br>
<br>
</div></div></blockquote></div><br></div>