Is zero the same as empty?

dunbarx at aol.com dunbarx at aol.com
Mon Oct 27 14:55:51 EDT 2014


Jacque.


Also true for "-300"


But your point is interesting, the cat is content until called upon to act. But, noneTheLess, this:


on mouseUp
  local b
  answer b + 1
end mouseUp


Also works just fine, thank you, and therefore the engine still knows what to do, happily typing on the fly like it always did, correctly, thank goodness, even with numeric calculations dealing with empty.  The "0" seems just wrong. If the above handler did not treat empty properly, then I would agree with your cat.


Craig



-----Original Message-----
From: J. Landman Gay <jacque at hyperactivesw.com>
To: How to use LiveCode <use-livecode at lists.runrev.com>
Sent: Mon, Oct 27, 2014 2:25 pm
Subject: Re: Is zero the same as empty?


On 10/27/2014, 11:20 AM, Graham Samuel wrote:
> 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?

Empty is sort of a Schrödinger variable and changes its state depending 
on how you look at it. If it is used in a numeric calculation it resoves 
to zero. Otherwise it resolves to empty. You don't need to do anything 
in particular, the engine handles that. In your tests, neither t1= empty 
and t1= 0 force an evaluation, so both are true. But zero and empty are 
not equivalent (one is a numeric value, one has no value at all,) so 
that evaluation is false. When you specifically put empty into t1, then 
it no longer equals zero.

In a handler that calculates empty variables in a math operation, you 
will always get the right answer. If you only need to see if the 
variable has a particular value, something like this always resolves 
correctly:

if t1 < 1 then... -- true for both zero and empty

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com


_______________________________________________
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