Internal or external procedures, and built-in functions, can be called as functions using the following syntax. The result of the function call is processed in place as a term within the current instruction clause.
|functionName( [ argumentExpression [ , argumentExpression [ , ...etc ] ] )|
This invokes an internal or external procedure named functionName, or a built-in function, as a function. A series of arguments can optionally be prepared by the argumentExpression values. These arguments can be acquired in the invoked procedure by using either the parse arg or arg instructions, or the arg built-in function. The invoked procedure MUST return a result which is provided in place as a term within the current instruction clause.
The name provided as functionName can be provided as a quoted string -- e.g. 'X2C'. When it is a quoted string, an internal procedure is not invoked, and a built-in function or external procedure is invoked instead. When a built-in function is invoked, using this technique, the name in quotes should be in upper case.
The search order for the target procedure, or built-in function is:
The mechanism for locating and activating an external procedure is implementation-dependent.
Click here to study the procedure instruction.
Click here to review the structure of Rexx programs and procedures.
Note: if a function call starts where an instruction is expected, the instruction is processed as a command! You should be particularly careful if you use isolated function calls in other programming languages; such as, C, C++, C#, Java, etc.
The following is an example of a function call.
/* main program */ do n=1 to 5 say 'The factorial of' n 'is:' factorial( n ) end return factorial : procedure n = arg(1) if n = 1 then return 1 return n * factorial( n - 1 )
The processing state of the following information is saved when a function or subroutine call is performed. The state of this information is restored when the function or subroutine returns.
Here is another example of a series of function calls within a single assignment instruction.
vector = left( ' ', 8 * day1no ) || , overlay( ' > 'right( dayofmon, 2 )' < ' , , left( ' 1 2 3 4 5 ' || , ' 6 7 8 9 10 ' || , ' 11 12 13 14 15 ' || , ' 16 17 18 19 20 ' || , ' 21 22 23 24 25 ' || , ' 26 27 28 29 30 ' || , ' 31 ', (daysinmo * 8) ), , 1 + ((dayofmon-1) * 8) )