Functions are ubiquitous in TL Script. A function is a script expression that requires one or more inputs to be calculated. Most scripts used to parameterize user interface components in Top-Logic must be written as functions. The script usually expects an input (argument) from surrounding components. A function consists of the declaration of a parameter which names the expected input and an expression which refers to this parameter:
x -> $expr
Defines a function that expects an argument x and produces a value by evaluating the expression expr. In the expression, the value of the function argument can be accessed using the syntax $x (see Variables).
A function that expects multiple arguments is written as follows:
x -> y -> $expr-using-$x-and-$y
Functions can also be stored in a variable to be called at a later time (see Function application).
{
myFunc = x -> $x * 5;
}
For information on calling functions, see Function application.
x -> 5 * $x
Output: /
The input for x is multiplied by 5.
x -> y -> $x * $y
Output: /
Multiplies the inputs of x and y.
{
multiply = x -> 5 * $x;
}
Output: /
The function for mulitplication is stored in the variable multiply. This can be accessed with $multiply to execute it with apply(), for example.