Functions

In REXX, a function call can be written anywhere in an expression. The function performs the requested computation and returns a result. REXX then uses the result in the expression in place of the function call.

Think of a function as: You are trying to find someone's telephone number. You call the telephone operator and ask for the number. After receiving the number, you call the person. The steps you have completed in locating and calling the person could be labeled a function.

Generally, if the interpreter finds this in an expression,

name(expression)

it assumes that name is the name of a function being called. There is no space between the end of the name and the left parenthesis. If you leave out the right parenthesis, it is an error.

The expressions inside the parentheses are the arguments. An argument can itself be an expression; the interpreter computes the value of this argument before passing it to the function. If a function requires more than one argument, use commas to separate each argument.

Built-in Functions - Rexx has more than 50 built-in functions. A dictionary of built-in functions is in the Procedures Language 2/REXX Reference.

MAX is a built-in function that you can use to obtain the greatest number of a set of numbers:

MAX(number, number, ...)

For example:

   MAX(2,4,8,6) = 8
   MAX(2,4+5,6) = 9

Note that in the second example, the 4+5 is an expression. A function call, like any other expression, usually is contained in a clause as part of an assignment or instruction.


[Back: Advanced REXX Functions]
[Next: DATATYPE( )]