Administrator
|
| block |
block := [:i | Transcript cr; show: i]. 1 to: 10 do: [:i | block value: i+1] The above should print ten times. But it only prints the five even numbers. That is a bug isn't it? Aik-Siong Koh |
> Sent: Thursday, July 31, 2008 3:33 PM
> To: [hidden email] > Subject: [squeak-dev] Serious bug in 3.10 > > > | block | > block := [:i | Transcript cr; show: i]. > 1 to: 10 do: [:i | block value: i+1] > > The above should print ten times. But it only prints the five > even numbers. > That is a bug isn't it? > > Aik-Siong Koh Try this.. block := [:f | Transcript cr; show: f]. (1 to: 10) do: [:f | block value: f+1] And you'll see that likely, to:do: is being inlined by the compiler and causing something funny like allowing you to increment the loops index var causing it to skip a number each iteration. Ramon Leon http://onsmalltalk.com |
In reply to this post by askoh
askoh wrote:
> | block | > block := [:i | Transcript cr; show: i]. > 1 to: 10 do: [:i | block value: i+1] > > The above should print ten times. But it only prints the five even numbers. > That is a bug isn't it? > > Aik-Siong Koh > More of a "known limitation" than a bug... due to the fact that squeak does not have proper closures. try | block | block := [:j | Transcript cr; show: j]. 1 to: 10 do: [:i | block value: i+1] Keith |
> askoh wrote: > > | block | > > block := [:i | Transcript cr; show: i]. > > 1 to: 10 do: [:i | block value: i+1] > > > > The above should print ten times. But it only prints the > five even numbers. > > That is a bug isn't it? > > > > Aik-Siong Koh > > > More of a "known limitation" than a bug... due to the fact > that squeak > does not have proper closures. > > try > > | block | > block := [:j | Transcript cr; show: j]. > 1 to: 10 do: [:i | block value: i+1] > > Keith I was going to say that, but why does it work using (1 to: 10) do: rather than 1 to: 10 do:, seems related to #to:do: being inlined? Ramon Leon http://onsmalltalk.com |
2008/8/1 Ramon Leon <[hidden email]>:
> >> askoh wrote: >> > | block | >> > block := [:i | Transcript cr; show: i]. >> > 1 to: 10 do: [:i | block value: i+1] >> > >> > The above should print ten times. But it only prints the >> five even numbers. >> > That is a bug isn't it? >> > >> > Aik-Siong Koh >> > >> More of a "known limitation" than a bug... due to the fact >> that squeak >> does not have proper closures. >> >> try >> >> | block | >> block := [:j | Transcript cr; show: j]. >> 1 to: 10 do: [:i | block value: i+1] >> >> Keith > > I was going to say that, but why does it work using (1 to: 10) do: rather > than 1 to: 10 do:, seems related to #to:do: being inlined? > #to:do: is a hacky compiler optimization, which replaces true messages. :) Someday its can be removed, when VM will be powered by good JIT > Ramon Leon > http://onsmalltalk.com > > > -- Best regards, Igor Stasenko AKA sig. |
In reply to this post by askoh
On Thu, Jul 31, 2008 at 3:32 PM, askoh <[hidden email]> wrote:
yes, but its ancient. It is to do with the implementation of blocks and specifically block temporaries. Both blocks bind to the same "i". So when you evaluate
block value: i + 1 the 1 to: do:'s i gets incremented. Try this with my closure implementation (http://www.mirandabanda.org/cogblog/downloads/) and it is fixed.
Aik-Siong Koh |
In reply to this post by Ramon Leon-5
On Thu, Jul 31, 2008 at 3:54 PM, Ramon Leon <[hidden email]> wrote:
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.
HTH |
In reply to this post by Ramon Leon-5
Ramon Leon <ramon.leon <at> allresnet.com> writes:
> > > Sent: Thursday, July 31, 2008 3:33 PM > > To: squeak-dev <at> lists.squeakfoundation.org > > Subject: [squeak-dev] Serious bug in 3.10 > > > > > > | block | > > block := [:i | Transcript cr; show: i]. > > 1 to: 10 do: [:i | block value: i+1] > > > > The above should print ten times. But it only prints the five > > even numbers. > > That is a bug isn't it? > > > > Aik-Siong Koh > > Try this.. > > block := [:f | Transcript cr; show: f]. > (1 to: 10) do: [:f | block value: f+1] > > And you'll see that likely, to:do: is being inlined by the compiler and > causing something funny like allowing you to increment the loops index var > causing it to skip a number each iteration. > > Ramon Leon > http://onsmalltalk.com > > Yes but: block := [:f | Transcript cr; show: f]. (1 to: 10) do: [:f | block value: f+1. block value: f]. does not behave much better... the 10 loops are performed, but since the blocks share same temporary f, things are still a bit strange. You need to use different argument names, NewCompiler or Eliot's closures. |
> >
> > And you'll see that likely, to:do: is being inlined by the > compiler and > > causing something funny like allowing you to increment the > loops index var > > causing it to skip a number each iteration. > > > > Ramon Leon > > http://onsmalltalk.com > > > > > > Yes but: > > block := [:f | Transcript cr; show: f]. > (1 to: 10) do: [:f | block value: f+1. block value: f]. > > does not behave much better... > the 10 loops are performed, but since the blocks share same > temporary f, things > are still a bit strange. > > You need to use different argument names, NewCompiler or > Eliot's closures. Oh I agree, I wasn't suggesting a solution, I know the scope of the args is shared because of the lack of real closures. I was more inquiring why the behavioral difference between (to:) do: and to:do: since the latter is inlined but normally you'd expect them to be equivalent. Ramon Leon http://onsmalltalk.com |
Free forum by Nabble | Edit this page |