From ftm
Jump to: navigation, search
(Parentheses)
(Single Values)
Line 18: Line 18:
 
* an expression within '''''parentheses''''' such as '(1 + 2.3 / $4)'
 
* an expression within '''''parentheses''''' such as '(1 + 2.3 / $4)'
  
 +
=== Primitive values ===
 
Examples of '''''primitive''''' values are:
 
Examples of '''''primitive''''' values are:
 
* 1 ... an int
 
* 1 ... an int
Line 29: Line 30:
 
* -thirteen ... a symbol
 
* -thirteen ... a symbol
  
 +
=== Named values ===
 
'''''Named''''' values are defined by FTM definitions using ''ftm.object''.
 
'''''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:
 
The names, always representing a single value, are used in expressions with a leading dollar ('$'), as for example:
Line 34: Line 36:
 
* $myobject
 
* $myobject
  
 +
=== Elements and properties of objects ===
 
An '''''element''''' of an object can be accessed with FTM expressions using brackets ('[ ]'), as for example:
 
An '''''element''''' of an object can be accessed with FTM expressions using brackets ('[ ]'), as for example:
 
* $myvec[0]
 
* $myvec[0]
Line 40: Line 43:
 
* {0 1 2.3 $four}[$1]
 
* {0 1 2.3 $four}[$1]
  
 +
=== Numbered arguments
 
Numbered '''''arguments''''' ('$1', '$2', '$3' etc) are especially useful in the FTM message box and can be used in the ''expr'' object. In expressions of FTM definitions with ''ftm.object'' they don't make sense and generate an error.
 
Numbered '''''arguments''''' ('$1', '$2', '$3' etc) are especially useful in the FTM message box and can be used in the ''expr'' object. In expressions of FTM definitions with ''ftm.object'' they don't make sense and generate an error.
  
 +
=== Tuples ===
 
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 (they don't have any methods that allow changing their size or thier values) they can be used in a similar way as lists, giving the possibilty to create tuples that contain tuples). Example of tuples are:
 
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 (they don't have any methods that allow changing their size or thier 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 three $four}

Revision as of 08:21, 13 July 2007

FTM expressions are used in the following contexts

  • the FTM message box ... the ftm.mess external
  • FTM definitions ... the ftm.object external
  • FTM externals ... arguments of any other FTM external
  • the expr class/object ... a class just like fmat or dict representing an expression

The syntax of FTM expressions is an extension of the Max list and message syntax known from the Max message box and externals.

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 primitive value (int, float, symbol) such as '1', '2.3' and 'four'
  • 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 within parentheses such as '(1 + 2.3 / $4)'

Primitive values

Examples of primitive 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

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

Elements and properties of objects

An element of an object can be accessed with FTM expressions using brackets ('[ ]'), as for example:

  • $myvec[0]
  • $mymat[0 0]
  • $mydict[x]
  • {0 1 2.3 $four}[$1]

=== Numbered arguments Numbered arguments ('$1', '$2', '$3' etc) are especially useful in the FTM message box and can be used in the expr object. In expressions of FTM definitions with ftm.object they don't make sense and generate an error.

Tuples

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 (they don't have any methods that allow changing their size or thier 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!)

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

Parentheses

Parentheses in FTM expressions – '(' and ')' – always will (try to) evaluate the contained elements to a single value.

Inside parentheses the following (sub-)expressions are allowed:

  • 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)'
  • the definition of a variable local to the expression such as '(x := $1 * 3.14159)'
  • an assignement such as '($x = 7)' or '($x += 0.5)' or ('$mydict[0] = zero)' or '($myfmat[0 0] += 0.1)'
  • a function call such as '(random -90 0)'
  • a method call such as '($myobj set 7 9.8 ten)'

Infix expressions

Operators such as +, -, *, / are in fact only evaluated within infix expressions.

... to be contiuned!