success story and "for" loop bug report

4 views
Skip to first unread message

hrc

unread,
Nov 4, 2008, 7:31:07 AM11/4/08
to KTurtle; an eduactinal programming environment

dear list, i want to tell you that i successfully used kturtle to
introduce freshmen to simple programming.
i have explained variables, function definitions and of course some
nice turtle graphics drawings.

everything works quite nice so far, but the "for" loop is buggy !


try the code below:
(Version 0.8 beta, running in kde 4.1.2 under windows - direct binary
from kde windows installer)

-----------------------------------------------
learn sum $n
{
$x = 0
for $a = 1 to $n
{
$x = $x + 1
}

print $x
forward 10
}

sum 20
-----------------------------------------------

suddenly, $x is not known inside the for loop . but the code works, if
"for" gets replaced by a simple

repeat $n

but the for loop works again, if used outside of a function.

Niels Slot

unread,
Nov 4, 2008, 12:37:40 PM11/4/08
to kdeedu-...@googlegroups.com
Hi,

Nice to know you're using KTurtle with success. Too bad to hear about the for-loop bug. If I find the time I'll have a look at it.

To everybody else who's reading this and using KTurtle with success, feel free to post photo's or success stories and feedback :).

Niels

2008/11/4 hrc <andre....@gmail.com>

Walter Schreppers aka Walle

unread,
Nov 19, 2008, 8:53:51 PM11/19/08
to KTurtle; an eduactinal programming environment
Aha that bug was also in an earlier wsbasic version (which was
probably the one cies started from). Cies tell me if it gives you some
difficulty (send a mail so it reminds me).
Then when I find the spare time I'll surely help you out. It's a
scoping problem as far as I can tell from the example given which
should be easy to resolve...

Now that I'm on the subject, how about we meet in real life sometime?
I'm going to skate at a cool park in rotterdam this saturday, no idea
if it's near to where you live in holland, it would be nice to talk
about kturtle's future (have some cool ideas on that ;) ).
And also want to give you major props for keeping up the good work/
effort into kturtle (and all other contributors)!

Kind regards,
Walter


On Nov 4, 6:37 pm, "Niels Slot" <nielss...@gmail.com> wrote:
> Hi,
>
> Nice to know you're using KTurtle with success. Too bad to hear about the
> for-loop bug. If I find the time I'll have a look at it.
>
> To everybody else who's reading this and using KTurtle with success, feel
> free to post photo's or success stories and feedback :).
>
> Niels
>
> 2008/11/4 hrc <andre.kra...@gmail.com>

cies

unread,
Nov 23, 2008, 1:03:00 PM11/23/08
to kdeedu-...@googlegroups.com
On Thu, Nov 20, 2008 at 7:23 AM, Walter Schreppers aka Walle
<schre...@gmail.com> wrote:
>
> Aha that bug was also in an earlier wsbasic version (which was
> probably the one cies started from). Cies tell me if it gives you some
> difficulty (send a mail so it reminds me).
> Then when I find the spare time I'll surely help you out. It's a
> scoping problem as far as I can tell from the example given which
> should be easy to resolve...

ehh. i dont know.. im quite busy now (got work -- suddenly).

> Now that I'm on the subject, how about we meet in real life sometime?
> I'm going to skate at a cool park in rotterdam this saturday, no idea
> if it's near to where you live in holland, it would be nice to talk
> about kturtle's future (have some cool ideas on that ;) ).

im a rotterdammer. yr welcome in my city. if you need to know anything
mail me privately..

currently im in india, so i cant make it personally. i will come back
someday and then its a good idea to meet up. niels is form a'dam, also
not to far.


> And also want to give you major props for keeping up the good work/
> effort into kturtle (and all other contributors)!

cheers.

_c.

Niels Slot

unread,
Nov 26, 2008, 4:26:51 PM11/26/08
to kdeedu-...@googlegroups.com
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....@gmail.com>

Walter Schreppers aka Walle

unread,
Nov 27, 2008, 4:29:27 PM11/27/08
to KTurtle; an eduactinal programming environment

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>

cies

unread,
Nov 28, 2008, 2:04:28 AM11/28/08
to kdeedu-...@googlegroups.com
> 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...

hmmm... interesting.. pity i have zero time to look at it for a while.. bummer.

> PS: just noticed the google group has a spelling error : 'eduactinal
> prog...' instead of 'educational prog...' ;)


fixed it.


> To Cies : Cewl, are u in india for work or holiday?

i came here to travel, the picked up some work to pay for more travel,
now nearly overworked and in need for a holiday ;)

Reply all
Reply to author
Forward
0 new messages