A function is a named closure: it has input parameters which are passed to the body of the function. The body comprises one or multiple expressions and return a value, which is the return value of the function.
Functions are declared and defined in a function definition file.
Note: PDS comes with two function editors, the text function editor and the visual function editor, which serve to create two different types of function definition files: When using the visual function editor, the output is an XML file with the declarations and definitions. The text function editor allows you to declare and define your functions as text. This section deals exclusively with the syntax of functions when they are defined as text. For more information on how the functions are declared and defined in PDS, refer to Functions in PDS guide.
To define a function use the following syntax:
Methods define their visibility:
Function parameters can be flagged as:
String... name
To define the default value of a parameter, use the <PARAM_TYPE> <PARAM_NAME> = <DEFAULT_PARAMETER_VALUE>
. Note that to assign the default value, =
is used.
When implementing a function as a Java method, use the native keyword followed by the java method path that implements the function instead of the {<implementation>}
, for example, native com.whitestein.lsps.example.myfunction;
.
Note: The native implementation then receives the current context as its parameter.
Individual functions are declared and defined with the following syntax:
A function declaration can have the following annotations:
@Status (<STATUS_NAME>)
@Meta(key1 -> value1, key2 -> value2, ...)
Function calls are calls to function definitions which are special kinds of closures defined in a function definition: Function definitions are model elements which cannot be created directly in the Expression Language; however, you can call functions and use their return value in your expressions.
A function call follows the syntax
or alternatively
The explicit definition of parameter names is useful if a parameter is not required and has a default value.
Example function call:
If a function uses type parameters, their types are inferred. However, you can define the types explicitly if required:
The list of types in <COMMA_SEPARATED_TYPES>
is used in the same order as the type parameters are defined. Note that you need to define the types for all type parameters.
A function call is resolved into the function based on the call arguments: overloading is supported.
Call to a Standard Library function with the types of type parameters: