| 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: squeak-dev@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
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
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 ramon.leon@allresnet.com:
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
On Thu, Jul 31, 2008 at 3:54 PM, Ramon Leon ramon.leon@allresnet.comwrote:
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?
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
Ramon Leon http://onsmalltalk.com
On Thu, Jul 31, 2008 at 3:32 PM, askoh askoh@askoh.com 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?
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
-- View this message in context: http://www.nabble.com/Serious-bug-in-3.10-tp18764850p18764850.html Sent from the Squeak - Dev mailing list archive at Nabble.com.
squeak-dev@lists.squeakfoundation.org