From ftm
Jump to: navigation, search
Line 1: Line 1:
This is a simple reference for the EXPR class.
+
This is a simple exaplanation for the use of the EXPR class.
  
 
== Creation - Elements of the call ==
 
== Creation - Elements of the call ==
  
An EXPRession is a sentence which can be applied to the content of an FMAT or an FVEC. It can be created in an FTM.object (class expr) or in an FTM.message.  In both case, it shares the same syntax:  
+
An EXPRession is a sentence which can be applied to the content of an FMAT or an FVEC. It can be created in an [[ftm.object]] (class expr) or in an FTM message box [[ftm.mess]].  In both case, it shares the same syntax:  
  
1_ it starts with expr  
+
# it starts with expr  
 
+
# it is surrounded by simple quotes ' '
2_ it is surrounded by simple quotes ' '
+
# it is then encapsulated within parenthesis (to be executed like all of FTM's code)
 
 
3_ it is then encapsulated within parenthesis (to be executed like all of FTM's code)
 
  
 
For example, the expression returning the value 1 is
 
For example, the expression returning the value 1 is
Line 23: Line 21:
 
There are two places you can create a new expr instance:
 
There are two places you can create a new expr instance:
  
* within a ftm.object
+
* within a [[ftm.object]]
  
 
as shown in the ftm.class.expr.maxhelp document. On the left, you put the expression, on the right its name, the latter being the way to call the expression
 
as shown in the ftm.class.expr.maxhelp document. On the left, you put the expression, on the right its name, the latter being the way to call the expression
  
* within ftm.mess
+
* within [[ftm.mess]]
  
 
when it is used as an argument to a method to another object, like in the following example:
 
when it is used as an argument to a method to another object, like in the following example:
Line 35: Line 33:
 
== Scope of variables ==
 
== Scope of variables ==
  
In the previous example, you could be tempted to use $1 and $2 to choose the boundaries of the random function within the expressionm but the variables $1 and $2 would not refer to the ftm.mess inputs, but to the expression variables.  We therefore need to pass those variables local to the ftm.mess to our newly created instance of expr by doing the following:
+
In the previous example, you could be tempted to use $1 and $2 to choose the boundaries of the random function within the expressionm but the variables $1 and $2 would not refer to the [[ftm.mess]] inputs, but to the expression variables.  We therefore need to pass those variables local to the [[ftm.mess]] to our newly created instance of expr by doing the following:
  
 
   ((new fmat 10 3) fill (new expr '(random $1 $2)') $1 $2)
 
   ((new fmat 10 3) fill (new expr '(random $1 $2)') $1 $2)
Line 69: Line 67:
  
 
** Find
 
** Find
 +
 +
[[Category:expr Class]] [[Category:Expressions]] [[Category:ftm.mess]]  [[Category:ftm.object]] [[Category:FTM Documentation]].

Revision as of 10:52, 6 July 2010

This is a simple exaplanation for the use of the EXPR class.

Creation - Elements of the call

An EXPRession is a sentence which can be applied to the content of an FMAT or an FVEC. It can be created in an ftm.object (class expr) or in an FTM message box ftm.mess. In both case, it shares the same syntax:

  1. it starts with expr
  2. it is surrounded by simple quotes ' '
  3. it is then encapsulated within parenthesis (to be executed like all of FTM's code)

For example, the expression returning the value 1 is

expr '(1)'

You can use all the FTM Functions available to create your expression. Moreover, $1, $2, etc will be replaced by values passed to your instance of expr.

For example, the expression returning the sinus of its input is

expr '(sin $1)'

There are two places you can create a new expr instance:

as shown in the ftm.class.expr.maxhelp document. On the left, you put the expression, on the right its name, the latter being the way to call the expression

when it is used as an argument to a method to another object, like in the following example:

((new fmat 10 3) fill (new expr '(random 1 3)'))

Scope of variables

In the previous example, you could be tempted to use $1 and $2 to choose the boundaries of the random function within the expressionm but the variables $1 and $2 would not refer to the ftm.mess inputs, but to the expression variables. We therefore need to pass those variables local to the ftm.mess to our newly created instance of expr by doing the following:

 ((new fmat 10 3) fill (new expr '(random $1 $2)') $1 $2)

Special Variables

Depending of context of use, an expr instance has access to some specific variables

  • FMAT
    • Fill
      • $row
      • $col
      • $self
    • Apply
      • $x
      • $self
    • Lookup
    • Find
  • FVEC
    • Fill
      • $idx
      • $self
    • Apply
      • $x
      • $self
    • Lookup
    • Find.