Using Numbers with Units
In SenseTalk, you can use numbers, either as numerals or text, for many types of operations and comparisons. Numbers often represent a quantity of some particular type, not merely an abstract value. For instance, the area of a rectangle might be referenced as "9 square inches" or an account balance might contain $698.53.
SenseTalk lets you associate a unit type such as inches or dollars with a number to add meaning and relevance. Assignments to variables and calculations using those values maintain and convert units as needed.
Working with Units
To specify a numeric value with a unit type, you include the unit name after the value. (The exception to this rule is the dollar symbol — $ — as described below.) SenseTalk recognizes singular, plural, and abbreviated unit names as well as "square" and "cubic" modifiers for area and volume:
put 3 ft --> "3 feet"
set weight to four grams
put 9 sq in --> "9 square inches"
Note: You do not include a period with unit abbreviations.
You can use chained values of the same type, with one value after another or with values joined by and
. Such representations are commonly used for weight or distance measurements:
put 6 ft 3 in --> "6.25 feet"
set weight to 2 pounds and 3 ounces
put weight --> "2.1875 pounds"
As you begin to see in the examples above, you can mix units in your expressions. Units are preserved or converted as needed in assignments and calculations:
put 3 ft into width
add 1 yard to width -- 1 yard is automatically converted to 3 ft in order to add it to the existing width
put width --> "6 feet"
put width * 4 feet into area
put area --> "24 square feet"
add 2 liters to area -- throws a mismatched units exception
You can combine units to form complex unit types such as speed (distance per timeInterval) or volume (length times width times depth):
set speed to 25 mi/hr
put speed --> "25 miles per hour"
put 3 hrs 45 min * speed --> "93.75 miles"
set accelerationOfGravity to 32 ft/s^2
set flow to 5 gallons per minute
set clickRate to 500/hr
set price to $5.96 per lb -- same as: 5.96 dollars per pound
set weight to 4 oz
put price * weight --> "$1.49"