A
function is a sequence of instructions
that can receive data, process it, and return a value. In REXX, there
are several kinds of functions:
- Built-in functions are built into the language processor. More
about built-in functions appears later in this chapter.
- User-written functions are those an individual user writes or
an installation supplies. These can be internal or external. An internal function is part of the current program that
starts at a label. An external function is a
self-contained program or program outside the calling program. More
information about user-written functions appears in section Subroutines and Functions.
Regardless of the kind of function, all functions return
a value to the
program that issued the function call. To call a function,
type the function name immediately followed by parentheses enclosing
arguments to the function (if any).
There can be
no space between the function name and the left parenthesis.
function(arguments)
A function call can contain up to 20 arguments separated by commas.
Arguments can be:
- Constant
function(55)
- Symbol
function(symbol_name)
- Option that the function recognizes
function(option)
- Literal string
function('With a literal string')
- Unspecified or omitted
function()
- Another function
function(function(arguments))
- Combination of argument types
function('With literal string', 55, option)
function('With literal string',, option) /* Second argument omitted */
All functions must return values. When the function returns a value,
the value replaces the function call. In the following example, the
language processor adds the value the function returns to 7 and produces
the sum.
SAY 7 + function(arguments)
A function call generally appears in an expression. Therefore a
function call, like an expression, does not usually appear in an instruction
by itself.