(→Single Values) |
(→Parentheses) |
||
Line 67: | Line 67: | ||
* an infix expression such as '(4 + 5.5 / $six)' | * an infix expression such as '(4 + 5.5 / $six)' | ||
* a prefix expression such '(random -90 0)' or '($myobj set 7 9.8 ten)' | * a prefix expression such '(random -90 0)' or '($myobj set 7 9.8 ten)' | ||
+ | |||
+ | |||
+ | ... to be contiuned! |
Revision as of 15:33, 6 June 2007
FTM expressions are used in the following contexts
- the FTM message box (ftm.mess)
- FTM definitions (ftm.object)
- the expr class/object
The syntax is basically always the same appart from minor context dependent details.
Single Values
The values in FTM expressions can be int, float, symbol or references to FTM object. Single values can be represended by the following items:
- a simple value (int, float, symbol) such as '1', '2.3' and 'three'
- a named value such as '$myobj'
- an element of an object such as '$myobj[7]'
- a numbered argument such as '$1', '$2', etc.
- a tuple such as '{1 2.3 three $four}'
- an expression between parentheses such as '(1 + 2.3 / $4)'
Examples of simple values are:
- 1 ... an int
- -2 ... an int
- 2.3 ... a float
- -4. ... a float
- 5.67e-4 ... a float
- .89 ... a float
- ten ... a symbol
- 11-12 ... a symbol (because no space!)
- -thirteen ... a symbol
Named values are defined by FTM definitions using ftm.object. The names, always representing a single value, are used in expressions with a leading dollar ('$'), as for example:
- $x
- $myobject
Numbered arguments are useful in the FTM message box and can be used in the expr object , but they give error in expressions of FTM definitions with ftm.object.
A tuple is an FTM object pretty much like an fmat or a dict and can show up in expressions with braces ('{ }'). The elements of a tuple are single values separated by blancs. The single value is a reference to a tuple. Since tuples are immutable objects (tuples don't have any methods that allow changing the size or values) they can be used in a similar way as lists, giving the possibilty to create tuples that contain tuples). Example of tuples are:
- {1 2.3 three $four}
- {1 2 3 {4 5 6} 7}
- {1 + 2 + 3 + 4} (7 elements!)
An element of an object can be accessed with FTM expressions using brackets ('[ ]'), as for example:
- $myvec[0]
- $mymat[0 0]
- $mydict[x]
- {zero one two three}[$1]
Operators other than '$', '[ ]', '{ }' are not evaluated outside of parentheses (see below).
Lists
Single values can be concatenated to argument lists (in the message box lists or messages) with spaces like:
- 1 2.3 three
- 4 + 5.5 / six (this is a list of 5 elements)
- $myobj set 7 9.8 ten
Argument lists within parentheses will be evaluated (see below).
Argument lists are not to be mixed up with tuples that can show up in FTM expressions. Tuples have braces around thier elements and are actually FTM objects pretty much like fmat and dict.
Parentheses
Parentheses in FTM expressions – '(' and ')' – always will (try to) evaluate the contained elements to a single value.
Inside parentheses you'd have either one
- a value such as '(1)' or '($x)' or '($mydict[x])' (in which case the parentheses are useless)
- an infix expression such as '(4 + 5.5 / $six)'
- a prefix expression such '(random -90 0)' or '($myobj set 7 9.8 ten)'
... to be contiuned!