Creating a new scope for the forloop (actually every time { or 'begin'
in wsbasic is used) is correct.
But the getId function in the executer class must be doing something
wrong (my first guess).
Anyway I modified the code a bit so it works in wsbasic and it runs
fine there. So it must be a bug which was already resolved in the past
by myself but did not make it into kturtle:
wALLe-MAC:~/cppWork/wsbasic wschrep$ cat test.bas
n=5
x = 0
for a = 1 to n
begin
x = x + 1
end
print x
#forward 10
wALLe-MAC:~/cppWork/wsbasic wschrep$ ./wsbasic test.bas
5
To Cies : Cewl, are u in india for work or holiday?
To Niels: Don't think the strange fix is necessary it is probably
located in getId (like said, first guess). Maybe we should meet up on
a weekend
and have a nice hack and get kturtle's executer up to speed with the
current wsbasic version which should solve all these types of bugs.
Now that I
see this forloop bug it will probably open a whole range of other bugs
since recursion will be buggy too if scoping is going wrong in
getId...
Cya,
W.
PS: just noticed the google group has a spelling error : 'eduactinal
prog...' instead of 'educational prog...' ;)
On Nov 26, 10:26 pm, "Niels Slot" <
nielss...@gmail.com> wrote:
> I've just committed a partly fix for this bug. There seem to be two things
> going wrong here. First, it was impossible to have other variables then the
> counter variable in a for loop opening line. In the example the value of $n
> never got resolved. That problem is fixed in current SVN trunk and the 4.1
> branch. A fix for this should therefore definitely be in 4.2 beta 2 and
> 4.1.4.
>
> The second problem is that you can't access a variable from outside the for
> loop within the for loop. In the example this means that the $x variable
> inside the for loop is a different one then the $x outside the for loop.
> I've already got a simple fix for this, but it's not pretty. The main
> problem is that when we're entering a for loop, we push it to the function
> stack. (Which seems a bit weird, but works..) Because it's on the function
> stack it has a different variable table. The simple fix would simply be to
> not give it a new different variable table, but just link the current one. I
> think a cleaner fix would be not the put it on the function stack at all
> (it's not a function anyways..). I hope to find the time to try out this
> cleaner fix. Any comment from Cies or Walter would of course be welcome.
>
> Niels
>
> 2008/11/4 hrc <
andre.kra...@gmail.com>