Chapter 7. Functions

Table of Contents
Syntax
Functions and Subroutines
Return Values
Built-in Functions

A function is an internal, built-in, or external routine that returns a single result object. (A subroutine is a function that is an internal, built-in, or external routine that might return a result and is called with the CALL instruction.)

Syntax

A function call is a term in an expression calling a routine that carries out some procedures and returns an object. This object replaces the function call in the continuing evaluation of the expression. You can include function calls to internal and external routines in an expression anywhere that a data term (such as a string) would be valid, using the following notation:

                   +-,--------------+
                   V                |
>>-function_name(----+------------+-+--)-----------------------><
                     +-expression-+

The function_name is a literal string or a single symbol, which is taken to be a constant.

There can be any number of expressions, separated by commas, between the parentheses. These expressions are called the arguments to the function. Each argument expression can include further function calls.

Note that the left parenthesis must be adjacent to the name of the function, with no blank in between. (A blank operator would be assumed at this point instead.) Only a comment can appear between the name and the left parenthesis.

The arguments are evaluated in turn from left to right and the resulting objects are then all passed to the function. This function then runs some operation (usually dependent on the argument objects passed, though arguments are not mandatory) and eventually returns a single object. This object is then included in the original expression as though the entire function reference had been replaced by the name of a variable whose value is the returned object.

For example, the function SUBSTR is built into the language processor and could be used as:

N1="abcdefghijk"
Z1="Part of N1 is: "substr(N1,2,7)
/* Sets Z1 to "Part of N1 is: bcdefgh" */

A function can have a variable number of arguments.You need to specify only those required. For example, SUBSTR("ABCDEF",4) would return DEF.