TAL Programmer's Guide

Using Procedure Options
Using Procedures
11–8 096254 Tandem Computers Incorporated
Declaring Functions A function is a procedure or subprocedure that returns a result to the caller. You
declare a function as you would a procedure, plus you specify:
The data type of the result value to be returned by the function
A RETURN statement that returns the result (and optionally a condition code)
For example, you can declare a function that has two formal parameters, multiplies
them, and returns an INT result to the caller:
INT PROC mult_function (var1, var2); !INT return type
INT var1, var2; !Declare formal parameters
BEGIN
RETURN var1 * var2; !RETURN statement returns result
END; ! and control to caller
Callers normally invoke functions by using the function identifiers in expressions. For
example, an assignment statement in a procedure can invoke the preceding
MULT_FUNCTION, passing two actual parameters to it:
PROC caller; !Declare CALLER
BEGIN
INT num1 := 5,
num2 := 3,
answer;
answer := mult_function (num1, num2);
!Assignment statement invokes
END; ! MULT_FUNCTION
For information on returning condition codes, see the RETURN statement in
Section 12, “Controlling Program Flow.”
Declaring FORWARD
Procedures
A FORWARD procedure declaration lets you call a procedure before you declare the
procedure. You can then declare the procedure anywhere in the same compilation
unit.
To declare a FORWARD procedure, specify the FORWARD keyword in place of the
procedure body. For example, you can declare PROC1 as a FORWARD procedure,
declare PROC2 which calls PROC1, and finally declare the body of PROC1:
PROC proc1 (param1, param2); !Declare PROC1 as a FORWARD
INT .param1, param2; ! procedure
FORWARD;
PROC proc2 MAIN; !Declare PROC2
BEGIN
INT i1 := 1;
CALL proc1 (i1, 2); !Call PROC1
END;
PROC proc1 (param1, param2); !Declare the real PROC1
INT .param1, param2;
BEGIN
param1 := param1 - param2;
END;