Function Definitions (Parameter Passing)

All of the basic Definition types can also become functions by defining them to accept passed parameters (arguments). The fact that it receives parameters doesn't change the essential nature of the Definition's type, it simply makes it more flexible.

Parameter definitions always appear in parentheses attached to the Definition's name. You may define the function to receive as many parameters as needed to create the desired functionality by simply separating each succeeding parameter definition with a comma.

The format of parameter definitions is as follows:

DefinitionName( [ ValueType ] AliasName [ =DefaultValue ] ) := expression;

ValueTypeOptional. Specifies the type of data being passed. If omitted, the default is INTEGER (see Value Types). This also may include the CONST keyword (see CONST) to indicate that the passed value will always be treated as a constant.
AliasNameNames the parameter for use in the expression.
DefaultValueOptional. Provides the value to use in the expression if the parameter is omitted. The DefaultValue may be the keyword ALL if the ValueType is SET (see the SET keyword) to indicate all possible values for that type of set, or empty square brackets ([ ]) to indicate no possible value for that type of set.
expressionThe function's operation for which the parameters are used.

Simple Value Type Parameters

If the optional ValueType is any of the simple types (BOOLEAN, INTEGER, REAL, DECIMAL, STRING, QSTRING, UNICODE, DATA, VARSTRING, VARUNICODE), the ValueType may include the CONST keyword (see CONST) to indicate that the passed value will always be treated as a constant (typically used only in ECL prototypes of external functions).

ValueDefinition := 15;
FirstFunction(INTEGER x=5) := x + 5;
          //takes an integer parameter named "x" and "x" is used in the
          //arithmetic expression to indicate the usage of the parameter
          
SecondDefinition := FirstFunction(ValueDefinition);
          // The value of SecondDefinition is 20
          
ThirdDefinition := FirstFunction();
          // The value of ThirdDefinition is 10, omitting the parameter