This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-06-26 07:37:59

IPurdie
New Scratcher
Registered: 2012-06-26
Posts: 1

Logic error

More a curiosity than a bug!

Using simple blocks, try entering:

say <[heoll] = [hello]>
(gives false)
say <[heoll] < [hello]>
(gives false)
say <[heoll] > [hello]>
(gives true)

So heoll and hello are obviously evaluated somehow numerically if one can be larger than the other. Fine, but...

set [TEST1 v] to [heoll]
set [TEST2 v] to [hello]
say <(TEST1) + (TEST2)>
(gives zero)

OK, so maybe hello evaulates to -1 and heoll evaluates to 0 ? Nope:

set [TEST1 v] to [heoll]
say <(TEST1) + [2]>
(result = 2)

set [TEST2 v] to [hello]
say <(TEST2) + [2]>
(result = 2)

So  heoll and hello *are* the same. But at the same time heoll > hello.

I know there's some technical reason in there for this to happen (maybe they're different by very, very small amounts?), and it's a silly little thing to spot but it does give a perfect example for my classes as to why they should be using variable types with proper definitions when we move onto Visual Basic!  smile

Offline

 

#2 2012-06-26 07:43:07

777w
Scratcher
Registered: 2009-02-10
Posts: 1000+

Re: Logic error

hmm very interesting

Offline

 

#3 2012-06-26 08:18:09

Wes64
Scratcher
Registered: 2011-08-19
Posts: 1000+

Re: Logic error

They are both undefined values, which when put into numerical functions such as equals and greater than, report 0. I don't know why the > one reports true, but it doesn't matter.

This isn't really a bug because you aren't supposed to use those functions that way anyways.


Experienced 2.0 Tester: Ask me questions!
Using Firefox 13.0, Flash plugin version 11.4.402.287, and Windows XP Professional.

Offline

 

#4 2012-06-26 08:34:42

operationDEADTREE
Scratcher
Registered: 2012-03-30
Posts: 42

Re: Logic error

Wes64 wrote:

They are both undefined values, which when put into numerical functions such as equals and greater than, report 0. I don't know why the > one reports true, but it doesn't matter.

This isn't really a bug because you aren't supposed to use those functions that way anyways.

why not?


http://desmond.imageshack.us/Himg26/scaled.php?server=26&amp;filename=maimsig32.png&amp;res=landing

Offline

 

#5 2012-06-26 08:37:47

Wes64
Scratcher
Registered: 2011-08-19
Posts: 1000+

Re: Logic error

operationDEADTREE wrote:

Wes64 wrote:

They are both undefined values, which when put into numerical functions such as equals and greater than, report 0. I don't know why the > one reports true, but it doesn't matter.

This isn't really a bug because you aren't supposed to use those functions that way anyways.

why not?

There is no mathematical solution for something like this.

<[apple] > [pie]>


Experienced 2.0 Tester: Ask me questions!
Using Firefox 13.0, Flash plugin version 11.4.402.287, and Windows XP Professional.

Offline

 

#6 2012-06-26 08:44:38

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Logic error

It's not an error at all, but rather some complicated casting. When you compare strings in the <> operators, it evaluates alphabetically, so that a<b, and g>e. When you use a string, any string, in a numerical insert, it treats it as having a value of 0.

Offline

 

Board footer