. Re: cross-stack globals, also, file inclusion

Dar Scott dsc at swcp.com
Sat Oct 25 13:15:16 EDT 2003


On Saturday, October 25, 2003, at 10:39 AM, Rob Cozens wrote:

>>> Programmer error, Jacque: constants 123 and "123" are not the same 
>>> and should not be used interchangeably.
>>
>> Do you mean as compiled?  Or as a matter of style?
>>
>> I have gotten the impression that these are exactly equivalent. When 
>> used in arithmetic in a handler, the value is converted to internal 
>> number form.
>
> Morning, Dar.
>
> IMF(oole's)O, the value of a constant is CONSTANT, and 123 does not 
> equate to "123".  It certainly doesn't in any other language I've 
> programmed in.

It does in some that I have programmed in.  (And it does in one I 
helped design.)

The dream is that values in Revolution are typeless.  Or, in another 
sense, have a single type and that type is string.  This has some rough 
edges, but is essentially it.  (The result of arithmetic and arrays 
don't fit well, but might in the future.)

The result of arithmetic is represented internally as a double float.  
That is almost invisible.  When we use that value in arithmetic, it is 
used.  When we use it as a string, it is converted.  Unfortunately, for 
historical reasons, it is converted using numberFormat.  This means 
that some information is lost and the string view depends on the 
context.  Also, the representation of non-number values of the double 
float have platform dependent string views.  The result is that the 
internal representation is not invisible.  There is no string that is 
exactly equivalent to the double float internal representation.

The primary advantages of the internal representation of numbers are 
speed of arithmetic and preservation of precision.  In my mind, it is 
simply an optimization.  New users might get confused of round() is 
needed in most displays, so the easy-to-forget numberFormat is used.  
The simplifying of things for a quick demo complicates things for all, 
newbies or not.

The 'is a number' is true for a numeral.  It is true for a string that 
looks like a number and for values that are double floats internally.  
In the latter case, when converted to a string, the value will be a 
numeral.


> I always use 123 to specify the integer and "123" to specify the 
> string; so I don't know if Revolution tries to coerce one to the 
> other.  I suppose one should try Jacque's example to see what the 
> MetaCard engine does with it; however I believe coercing the type of a 
> constant is not appropriate for a professional development tool.

The coercion of constants is common in programming languages.  I don't 
think that is an issue here.


This is one of two reasons I like to dynamically compute my constants 
at initialization or first use:
   1.  I can force it to be in internal numeric form (peeking past the 
above veil)
   2.  I can made some constants depend on others


A year ago I ran some tests that did some timing measurements that 
demonstrate a little about constants.  I don't know if I have it 
around.  Maybe I can reconstruct that.  The behavior might not be the 
same today, anyway.

Dar Scott






More information about the use-livecode mailing list