TIScript supports named and anonymous (lambda) functions.
Named functions are declared using following syntax:
//...function body
Where:
<function-name> is a function name, either: <nmtoken> , or <nmtoken1> ['.' <nmtoken2> ['.' <nmtoken3> ['.' … <nmtokenN> ]]] 1) <parameters> is a list of formal parameters of the function:[<parameter-name1> [, <parameter-name2> [, ... <parameter-nameN> ]]]
Anonymous function can be declared in place using following forms:
Nested functions (functions inside functions) are allowed.
The language supports optional parameters in function declarations:
Some parameters in the function declaration may have default value defined, for example:
Such function can be called with either two:
// r1 will be equal to 15 here
or three actual parameters:
// r2 will be equal to 6 here
Parameter with predefined value must not have non-optional parameter on its right in the list. In other words only last (or all) parameters can have default values.
a.k.a. Parameter vectors
There are situations when you will need to define functions with number of parameters unknown upfront. Such functions can be declared as:
In runtime variable
rest will contain array with actual parameters passed into the function. So after
r1 will contain value 10, and after
r2 will contain value 3
name1.name2.name3. … .nameN = function( <parameters> ) { <statements> }