FUNCTION func-spec

The FUNCTION keyword provides the reference to the specified function.

Syntax

FUNCTION [module-name.]function-name
  1. module-name is the name of an imported module.
  2. function-name is the name of a function defining in the current module or in an imported module.

Usage

Inside a MAIN or FUNCTION block, the FUNCTION keyword instructs the compiler to use the next symbol as the name of a function, rather than the name of a variable (the language allows the declaration of variables and functions with the same name in the same module).

The function specification following the FUNCTION keyword can be a single function name or a function name prefixed by a module name.

Note: The function referenced by the FUNCTION expression must be defined with a RETURNS clause. Otherwise, the compiler will produce the error -8419.

A FUNCTION func-spec expression is typically used to assign a variable defined with a TYPE referencing a function. It can also be used as parameter in a function call, but it cannot be combined with other expressions.

Example

IMPORT FGL mymodule

TYPE callback_function FUNCTION(p1 INT, p2 INT) RETURNS INT

FUNCTION add(p1 INT, p2 INT) RETURNS INT
    RETURN p1 + p2
END FUNCTION

...
    DEFINE v callback_function
    LET v = FUNCTION add  -- Assign function reference to the variable
...
    CALL process( FUNCTION add, ... ) -- Function reference passed as parameter
...
    LET v = FUNCTION mymodule.sub  -- Using a module prefix