Is zero the same as empty?

dunbarx at aol.com dunbarx at aol.com
Mon Oct 27 14:46:35 EDT 2014


Graham.


Normally, variables or parameters, in order to be created at all, have to have something put into them. At least in HC they did. But with such tools as the "local" command, you can create them by simply declaring them:



on mouseUp
   local a,b,c
   answer test(b)
end mouseUp


function test a,b,c
   return (param(2) = "") && (param(2) = "0")
end test



Both "true". Well, I am upset. Say it ain't so. These should not be "0". No way.  Zero is not nothing.


Craig



-----Original Message-----
From: Graham Samuel <livfoss at mac.com>
To: How to use LiveCode <use-livecode at lists.runrev.com>
Sent: Mon, Oct 27, 2014 12:21 pm
Subject: Is zero the same as empty?


I found that if a parameter of a handler or function, or indeed a local 
variable, (say t1) has never had a value placed in it, then

   t1 = 0

is true. I was surprised by this, since I thought all  unassigned variables were 
rendered empty by the engine, and that empty and zero were distinct.

But in the same script

   t1 = empty

is also true. Logically then, ‘empty’ is the same as ‘0’. However the statement

   0 = empty

evaluates to false. Furthermore if I make sure t1 is empty by

  put empty into t1

then

  0 = t1

yields false.

Am I going crazy? This issue matters to me as I am comparing numeric characters 
with a variable which is sometimes unassigned. I see that I must always assign a 
value to the variable, even it that value is empty!

Is this any kind of a bug, or is it just slightly strange behaviour on the part 
of the engine?

Graham
_______________________________________________
use-livecode mailing list
use-livecode at lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

 



More information about the use-livecode mailing list