Local variables
Local variables, defined by the word var, can be used in the expressions.
They are declared using the following syntax:
var x = f(a, b);
The type of the variable declared in this way is determined automatically - it is of the type of expression occurring to the right of the assignment = sign.
Variables are referenced later using the new vars data tree as follows:
f(a, vars::x)
This approach eliminates the possibility of ambiguity - you know which elements come from the local unnamed tree, and which are variables.
Variables can be of scalar type ( text, number, date, etc...) or tree type. The latter can be prepared with a mini-linq expression returning a list of records created ad-hoc.
An example of an expression that calculates the average of different fields from several differently filtered lists:
var a= from List where condition>100 select \{a=field1, b=field2\};
var b=from SecondList where condition2>50 select \{a=fieldX, b=fieldY\};
var c=vars::a+vars::b;
max(vars::c\a)
For example:
Using the data from our tree, we can build a simple financial score.
In addition to income var incomes let's define for ourselves expenses var expenses, which differ only in the value of the OperationCode field.
Our score will be how much money, in percentage terms, we put aside in our account in some analyzed period.
We refer to the variables through the vars:: tree:
(vars:: incomes - vars::expenses) / Balance
