Using the functions

Cascade Expressions: cascade call

Cascade Expressions

There are some places where you may use either literal value or cascade expression. These places are:

  • parameter's output cell,
  • parameter's input cell,
  • domain attribute value,
  • input level's property (source value).

There are 2 types of cascade expressions:

  • cascade get - redirects evaluation to given parameter,
  • cascade call - redirects evaluation to given function.

Basic information about cascade call:

  • every cascade call starts with $f symbol, which means cascade to function,
  • when cascading to function, you may pass arguments to that function,
  • when cascading to function, you may extract value from compound result.

Below you can see 3 basic usages of cascade expressions:

1) Cascade expression inside parameter's output cell:

2) Cascade expression used in domain attribute:

3) Cascade expression used in level source:

Cascade call

Everywhere you use Cascade call expression it redirects evaluation to given function and takes value that function returns.

Cascade call syntax:

cascade statement
meaning
$f fun
evaluates function fun and takes its result
$f fun (1, 5, active)
function is called with 3 arguments passed: "1", "5" and "active",note that arguments are always passed as string values
$f fun (1; 5; A,B,C)
if semicolon ; is present anywhere in arguments expression - Hyperon will use that semicolon as argument delimiter, otherwise it will use comma , as delimiter,
note that this call will pass 3 string arguments: "1", "5", "A,B,C"
$f fun (ctx:insured.age, 5)
you may pass values taken directly from current context by using ctx:path syntax,
note that this example will take first argument from current context
with standard context API: ctx.get( "insured.age" )
$f fun [ idx ]
if function returns compound result (ParamValue, MultiValue, java array, Collection or Iterable), then cascade call extracts element from position idx, where idx = 0 is first element
$f fun [ code ]
if function returns compound result (ParamValue, MultiValue or Map),
then cascade call extracts element associated with key = code - result.get(code)
$f fun (1, ctx:prd.code) [factor]
one more example: fun is called with 2 arguments, first is given as a literal,
second is taken from current context from prd.code path, and finally - Hyperon extracts "factor" field from function's compound result.

Implicit type conversion

Suppose, you have parameter P with level L1 of type T1, and function F returning value of type T2. If you use cascade call inside P[L1] pointing to F, then:

step 1: internally cascade call will return value of type T2, internally cascade
step 2: next, T2 will be converted to Holder,

  • conversion will meet Hyperon's conversion standards, see _dec(), _num(), _str(), _date(), _bool() conversion methods,
  • conversion may be lossy (eg. T1 is integer while T2 is number)

Example

Suppose we have function calc.factors and parameter client.factors defined as follows:

Function calc.factors:
function (age) {

    // normalize arguments (this is recommended as they may come as strings)
    age = _num( age );

    var factor1 = 1.0 + age/100;
    var factor2 = 3.0 + age/10;

    // return f1 mapped to factor1, and f2 mapped to factor2
    return util.map(
        'f1', factor1,
        'f2', factor2
    );
}
Parameter client.factors:
IN
insured.age
OUT
factor1 (integer)
OUT
factor2 (number)
0 - 30
1.0
3.0
31 - 40
1.1
$f calc.factors (ctx:insured.age) [f2]
41 - 50
1.2
$f calc.factors (50) [f2]
*
$f calc.factors (65) [f1]
$f calc.factors (50) [f2]

Below you can see parameter's results for some values of insured.age property:

insured.age
factor1
factor2
22
1.0
3.0
37
1.1
6.7
44
1.2
8.0
61
1.65
9.5