Nevron Open Vision Documentation
Advanced Formula Features

Scripting Features (Statements, Local Variables and Scopes)

In most of the cases you will write formulas that do not use the scripting features that NOV formulas provide. This is because the most common usage of formulas is to represent functional binding between multiple DOM properties (formulas are used in DOM formula expressions) or other values. There are cases however, when more complex formulas need to be authored and such cases are best solvable by using the scripting features present in NOV formulas. 

The scripting abilities of NOV formulas aim to extend formulas with the following imperative programming language features:

Imperative programming languages are such languages that execute a sequence of statements that change a program state. Statements themselves are constructed by expressions. In NOV formulas you use the ';' (semi-colon) char to separate the statements. In most programming languages the statement is usually not associated with a return value, however in NOV formulas a sequence of statements returns the last expression evaluation result, since NOV formulas must always return a value. For example:

10;20;30 - returns 30.

Having the ability to execute a sequence of statements is useless, unless you have the means to store the result of previously executed statements (i.e. keep a program state). In NOV formulas this is achieved with local variables. Local variables are identifier tokens, to which you can assign a value by using the assignment operator. For example:

a=10;b=20;a+b - returns 30.

A local variable needs to first be assigned with a value prior to being used.

a=10;a+b - throws an "Evaluation error. Use of unassigned local variable with name:b"

Each NOV formula is associated with a root scope. The ever present root scope ensures that you can write formulas that consist of a sequence of statements. There are cases when you may want to create a child scope. A child scope is such an expression from the formula that is enclosed in '{' '}' (curly braces).

Just like the root scope, child scopes can contain multiple statements and return the last expression evaluation result, as result for the scope. Local variables however declared inside a child scope are not visible in its parent scope and sibling scopes, but are visible in its descendant scopes. For example:

a=10;{b=20};a+b - throws an "Evaluation error. Use of unassigned local variable with name:b", because b is declared in a child scope and is not visible to the root scope.

a=10;{b=20;a+b} - returns 30, because a is declared in the root scope and is visible in the child scope.

Support for Measurement Units

NOV formulas feature support for measurement units. Measurement unit expressions need to be enclosed in '[' ']' (square brackets). Measurement unit expressions allow only a subset of the arithmetic operators (multiplication *, division /, exponentiation ^, unary plus and unary minus), parenthesis and base unit names or abbreviations. For example:

1 [mm] - evaluates to 1 [millimeter]

1 [millimeter / s] - evaluates to 1 [millimeter/second]

1 [mm^2 / (hour * g^3)] - evaluates to 1 [millimeter^2/(hour*gram^3)]

1 [mm^2 / (hour * g^-3)] - evaluates to 1 [millimeter^2*gram^3/hour]

Unit expressions are internally implemented as high precedence postfix unary multiplication operator, meaning that you can place unit expressions after any element that evaluates to an operand. For example:

(2 + 3) [mm] - evaluates to 5 [millimeter]

SUM(3, 2) [mm] - evaluates to 5 [millimeter]

(3 [day] + 2 [hour]) [mm] - evaluates to 3.08333333333333 [millimeter*day]

Unit expressions are internally normalized according to the following rules:

For example:

1 [mm / meter] - evaluates to 0.001

1 [mm^2 / meter] - evaluates to 0.001 [millimeter]

1 [mm^2 * in] - evaluates to 25.4 [millimeter^3]

Measurement unit algebra rules apply for operations with measures. For example:

5 [mm] + 10 [in] - evaluates to 259 [millimeter] 

5 [mm] + 10 [s] - throws "Evaluation error. Cannot convert unit [second] to unit [millimeter]. Units are from different dimensions"

5 [mm] * 10 [in] - evaluates to 1270 [millimeter^2] 

5 [mm] / 10 [in] - evaluates to 0.0196850393700787




Send Feedback