Expression-based attributes

Introduction

You can define an expression to specify how the values of an attribute are computed. For example : 

If amount > threshold 
  Then amount * MultiplierAlias + Level
  Else amount  
End 

Usage

On a derived attribute, the computed attribute edit screen presents the "COMPUTED USING" section that offers the choice between function mode and expression mode.

When switching to expression mode a configuration section appears which allows to enter the expression defining the indicator.

The following elements will help the user create an expression :

  • The user interface presents two combo boxes above the expression input text area :
    • The first one lists all the functions that can be used in expression mode. See List of functions (with Expression-based support)
    • The second one lists all the aliases of correctly defined inputs.
  • While typing an expression, the keyboard shortcut CTRL-SPACE will display an auto-complete menu which helps the user find functions and input aliases. This menu dynamically looks for functions and input aliases that begin with already typed characters.

Expressions syntax and grammar

Expressions can include:

  • Functions : the document List of functions (with Expression-based support) gives a detailed help about each supported function. 
    Example of a valid expression with nested functions calls :

    Max(alias1, Multiply(alias2, Add(alias3,alias4)), alias5)

    (warning)  All functions that exist in the "function" mode are supported except the following : 

    • Aggregations,

    • Baseline,

    • Baseline evaluate from threshold.

    • Evaluate from threshold.

  • Arithmetic, boolean and relational expressions. 
    • These expressions support :
      • artihmetic operators + (as binary operator) , - (as unary and binary operator) , * , / and % (modulo) 
      • boolean operators ||, &&, ^ and ! (not as unary operator)
      • relational operators <, >, <=, >=, == and !=
      • parentheses ( ) 
    • They are interpreted using the standard mathematical order of operators. 
      • For example :
        • alias1 + alias2 * alias3 is equivalent to alias1 + ( alias2 * alias3 )
        • alias1 || alias2 && alias3 is equivalent to alias1 || ( alias2 && alias3 )
      • The order of precedence of operators is as follows : 

        1 ()   Scope
        2 -  !
        Minus and Not unary operators
        3 *   /   % Multiplication, division, modulo
        4 +   - Addition and subtraction
        5 <   <=   >   >= Comparisons: less-than, ...
        6 ==   != Comparisons: equal and not equal
        7 && Logical AND
        8 ^ Exclusive Logical OR (XOR)
        9 || Logical OR
  • Input aliases : in expression mode the user can define new inputs using the "Add Input" button. 
    • An input may be either another attribute or a constant value.
    • For each input the user needs to define an alias. This input alias will then be used in the expression. Input aliases must start with a letter. The valid following characters of an alias are all alphanumeric characters and the _ character.
  • If-Then-Else statements such as : 
If aliasBoolean
Then alias1
Else alias2 + alias3
End

These statements give more comfort than their equivalent but also supported functional form : 

IfThenElse(aliasBoolean,
	alias1,
	alias2 + alias3)
  • Comments : expressions can include single line comments (starting with //) or multiple lines comments (enclosed by /* and */)
If aliasBoolean
Then alias1 // return first value
Else 
	/* return the sum of 
       alias2 and alias3 */
	alias2 + alias3
End

Expressions validation

Each time the expression or its inputs are updated the application automatically checks if there are no syntax or semantic errors. 

Syntactic checks verify that the elements composing the expression produce a well structured expression. Here are some examples of syntax errors :

  • missing comma: Add(ind1 ind2)
  • unexpected end of expression: ind1 +

Semantic checks ensure that the expression itself is meaningful. Here are some examples of semantic errors :

  • an alias used in the expression is not defined in the inputs section.
  • a function used in the expression is Unknown
  • a function or arithmetic expression is used with an incorrect number of parameters or parameters with incorrect types: text + integer, where text refers to a String input and integer to an integer input.
  • an expression cannot be defined by a single input alias only. A arithmetic expression or a function base expression is required.
  • If the user is editing an existing indicator and the expression type cannot be assigned to the indicator type.

If there are no errors, then the return type of the expression is evaluated and displayed.

Related Links