Conversion of Values
SenseTalk is a typeless language. That is, all values can be treated as text, and you never need to declare that a given variable will hold a particular type of value, such as numbers or dates or text, or lists of values. Internally, however, SenseTalk can hold values in different forms, converting from one representation to another as needed.
Understanding how and when these conversions occur, and the global properties that control the formatting, will let you take control of this process when necessary.
Automatic Conversion
SenseTalk converts values automatically to an appropriate internal representation as needed. When performing an arithmetic operation such as addition, for instance, the two values being added will be evaluated as numbers. The resulting value will be kept internally in numeric form until it is needed as text.
In most situations, SenseTalk's automatic value conversion will do what you want and provide the desired result. Occasionally, though, there can be surprises, so it's helpful to understand when these conversions take place and how you can control them. Consider the following example:
put ((1 + 2) & 4) + 5
When this statement is executed, SenseTalk first adds the numbers 1 and 2, getting the value 3, which is temporarily stored as a number. The next operation that is performed is to concatenate this value with 4. This is a text operation, so both values are converted to their text representation before being joined into a single text string. Finally, this result is converted back to a number so that it can be added to the number 5.
The final result displayed will be 39. Or will it? It turns out that the actual outcome may be 39, or 309, or 3009 or some other number, or it may result in an error, depending on the setting of the numberFormat
property when this statement is executed. Let's see how this can happen.
Consider that the numberFormat
property controls how a numeric value is formatted when it is converted to a text representation, including such things as the number of decimal places to show, and whether leading zeros should be displayed. In our example, the numbers 3 and 4 were converted to text form to concatenate them. The default setting of the numberFormat
property converts them to the text strings "3" and "4", resulting in the concatenated text "34". Using a number format that includes leading zeros (setting it to "00", for example) causes the numbers 3 and 4 to be represented in text form as "03" and "04", which concatenate as "0304". In order to add 5 to this string, it is converted to a number (304) giving the final result of 309.
Similar conversions happen when values stored internally as date or time values, or entire lists or property lists of values, are needed in a text format.