Chapter 5. using functions, What is a function, Example of a function – IBM SC34-5764-01 User Manual

Page 73: Chapter 5. using functions what is a function

Advertising
background image

Chapter 5. Using Functions

This chapter defines what a function is and describes how to use the built-in functions.

What is a Function?

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:

v

Built-in functions are built into the language processor. More about built-in functions appears later in this
chapter.

v

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 “Writing Subroutines and Functions” on page 58.

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:

v

Constant

function(55)

v

Symbol

function(symbol_name)

v

Option that the function recognizes

function(option)

v

Literal string

function('With a literal string')

v

Unspecified or omitted

function()

v

Another function

function(function(arguments))

v

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.

Example of a Function

Calculations that functions represent often require many instructions. For instance, the simple calculation
for finding the highest number in a group of three numbers, might be written as follows:

© Copyright IBM Corp. 1992, 2009

51

Advertising