Returning more than one value from a function

[Autolink] Menu

To write functions returning more than one value you can use the following technique.

 
/* simple program to show a technique using a function which returns  */
/* more than one value                                                */
/*                                                                    */
/* This example uses a variable character for the separator in the    */
/* returned value.                                                    */
/*                                                                    */

  say "Values returned by the function MyFunc:"
  parse value myFunc() with separator 2 rc1 (separator) rc2 (separator) rc3

  if separator <= "A" then
    say " The separator for the return codes is: ASCII(" || ,
        C2D( separator ) || ")"
  else
    say " The separator for the return codes is: " || ,
        separator

  say " rc1 = """ || rc1 || """"
  say " rc2 = """ || rc2 || """"
  say " rc3 = """ || rc3 || """"
exit 0

/* simple function - does nothing than returning three values         */
myFunc: PROCEDURE

  separator = "00"x     /* character to separate the values in the    */
                        /* returned string                            */
                        /* Note that this can be any value from "00"x */
                        /* to "FF"x not used in one of the return     */
                        /* codes. The calling procedure need not      */
                        /* know the value before calling this         */
                        /* function!                                  */


                        /* sample return codes                        */
  rc1 = 4
  rc2 = "TestRC"
  rc3 = 0

RETURN separator || rc1 || separator || rc2 || separator || rc3


[Back: Information saved during subroutine & function execution]
[Next: Catching CTRL-C]