Product SiteDocumentation Site

7.3. Return Values

A function usually returns a value that is substituted for the function call when the expression is evaluated.
How the value returned by a function (or any Rexx routine) is handled depends on whether it is called by a function call or as a subroutine with the CALL instruction.
Here are some examples of how to call a Rexx procedure:

Example 7.3. How to call Rexx procedures

call Beep 500, 100         /* Example 1: a subroutine call */
The built-in function BEEP is called as a Rexx subroutine. The return value from BEEP is placed in the Rexx special variable RESULT.
bc = Beep(500, 100)        /* Example 2: a function call   */
BEEP is called as a Rexx function. The return value from the function is substituted for the function call. The clause itself is an assignment instruction; the return value from the BEEP function is placed in the variable bc.
Beep(500, 100)             /* Example 3: result passed as  */
                           /*            a command         */
The BEEP function is processed and its return value is substituted in the expression for the function call, like in the preceding example. In this case, however, the clause as a whole evaluates to a single expression. Therefore, the evaluated expression is passed to the current default environment as a command.

Note

Many other languages, such as C, throw away the return value of a function if it is not assigned to a variable. In Rexx, however, a value returned like in the third example is passed on to the current environment or subcommand handler. If that environment is the default, the operating system performs a disk search for what seems to be a command.