Bug 156437 - Interpreting Logo Source Code, IF Statements Work Three in Ten Times.
Summary: Interpreting Logo Source Code, IF Statements Work Three in Ten Times.
Status: RESOLVED FIXED
Alias: None
Product: kturtle
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: unspecified Linux
: NOR normal (vote)
Target Milestone: ---
Assignee: Cies Breijs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-01-23 07:27 UTC by Iain Buclaw
Modified: 2008-08-21 04:34 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Iain Buclaw 2008-01-23 07:27:35 UTC
Version:           0.8 beta (using 4.00.00 (KDE 4.0.0), Debian packages)
Compiler:          gcc
OS:                Linux (i686) release 2.6.22-3-486

#/**This is a small program to teach my son the basics of programming and maths at the same time**/
$r = 0
repeat 10 {
	reset
	$x = random 1,10
	$y = random 1,10
	$a = 1
	$b = 1

#/**it goes wrong in the loops here downwards.**/
	while $a < 11 {
#/**tried it with 'for' loop too with no success.**/
		if (($x >= ($a - 0.5)) and ($x < ($a + 0.5))) {
#/**also tried it with different glues, this gave the best-ish result, but no different from others. Is this IF statement valid? It works every other time, why not all the time?**/
			$x = $a
		}
		$a = $a + 1
	}

	while $b < 11 {
		if (($y >= ($b - 0.5)) and ($y < ($b + 0.5))) {
			$y = $b
		}
		$b = $b + 1
	}
#/**Of the loops, approx. 3 times both worked,  twice neither worked and the rest either one or the other worked**/

	$in = ask "What is " + $x + " x " + $y + "?"
	if ($in == $x * $y) {
		message "Correct!"
		$r = $r + 1
#/**also to point out, if the messages where vice versa (Correct in the 'else' block) and the function was '!= $x*$y' a blank input would return the message 'Correct'**/
	}
	else {
		message "Wrong!"
	}
}
message "You got " + $r + " answers correct!"
#/**The fact that it works sometimes means that it must work, but there is something that stops it from working half the time.**/
Comment 1 Iain Buclaw 2008-01-23 07:33:54 UTC
What originally happened was that it would work. $x would get assigned to $a but then get reverted back to the original $x afterwards.

After slightly altering the code I got it to work. But it only found a solution half the time... It should cover every decimal number between 1 and 10 right?
Comment 2 Mauricio Piacentini 2008-01-26 14:57:57 UTC
It seems there is indeed a bug with if, apparently it does not work with even values? I need to check the source, but a simple way to reproduce this in 4.0:

This works:

reset
$a = 0
repeat 3 {
  $a=$a+1
  print $a
  if $a==1 {
    print "If ok"
  }
}
print "end"

This does not work (comparing to 2)


reset
$a = 0
repeat 3 {
  $a=$a+1
  print $a
  if $a==2 {
    print "If ok"
  }
}
print "end"

This works also (comparing to 3)


reset
$a = 0
repeat 3 {
  $a=$a+1
  print $a
  if $a==3 {
    print "If ok"
  }
}
print "end"

Showstopper, I will see if I can fix it in time for 4.0.1
Comment 3 Mauricio Piacentini 2008-01-28 20:53:50 UTC
Additional info: it happens when the IF scope is nested inside another scope. Somewhere the variableTable gets erased or is not read in the correct scope, so one iteration works, and the next fails.
Comment 4 Iain Buclaw 2008-02-02 04:07:57 UTC
Not to worry, as long as I am not going wrong, it's all nice to know!

Though I have made a small work around that does work, instead of while i used "repeat" loop and instead of incrementing the $string number by one, its been done by 0.5. Though the downside is that I takes up more time to do it this way.

repeat 18 [
 if $x < ($y + 0.5) [
  if $x > ($y - 0.5) [
   code
  ]
 ]
 if $x > ($y - 0.5) [
  if $x < ($y + 0.5) [
   code
  ]
 ]
 $y = $y + 0.5
]

I don't have the logo file on this computer, but I think this is the general layout of what I did, but it doesn't workout in my head, so I'll have to check later if this is what I used.

Though if I am right in this implementation, it would make sense that it is possible that it could work if the if scope is slightly messed up.

By the way, what do you think of my attempt to write an extrinsic "truncate" function? Am I going the right way about it? or would you suggest a better method?

Also, I must say this is a better program (though still in its early stages), I really noticed the better functionality with the intrinsic functions, It has a lot more potential for those "thinking outside the box" stuff.

Keep up the good work!
Thank-you.

Iain
Comment 5 Niels Slot 2008-02-02 11:02:46 UTC
Hi Iain,

I fixed this bug a few days ago. All the examples given by Mauricio in his second comment work correctly with KTurtle in KDE 4.0.1. KDE 4.0.1 is due to be release on the 6th of February.

Niels
Comment 6 Mauricio Piacentini 2008-08-21 04:34:51 UTC
Fixed in 4.0 release and 4.1