TAL Programmer's Guide
Using Procedure Options
Using Procedures
11–12 096254 Tandem Computers Incorporated
Passing Parameters Conditionally
As of the D20 release, you can pass a parameter or parameter pair to a VARIABLE or
EXTENSIBLE procedure based on a condition at execution time by using the
$OPTIONAL function. $OPTIONAL is evaluated each time the encompassing CALL
statement is executed:
If the conditional expression is true, the actual parameter is passed.
If the conditional expression is false, the actual parameter is not passed.
In the following example, parameter pair S:I is passed because I equals 1, which is less
than 9. Parameter J is not passed because J equals 1, which is not greater than 2.
PROC p1 (str:len, b) EXTENSIBLE;
 STRING .str;
 INT len;
 INT b;
 BEGIN
 !Lots of code
 END;
PROC p2;
 BEGIN
 STRING .s[0:79];
 INT i:= 1;
 INT j:= 1;
 CALL p1 ($OPTIONAL (i < 9, s:i), !Pass S:I if I < 9.
 $OPTIONAL (j > 2, j) ); !Pass J if J > 2.
 END;
You can use $OPTIONAL and $PARAM when one procedure provides a front-end
interface for another procedure that does the actual work:
PROC p1 (i, j) EXTENSIBLE;
 INT .i;
 INT .j;
 BEGIN
 !Lots of code
 END;
PROC p2 (p, q) EXTENSIBLE;
 INT .p;
 INT .q;
 BEGIN
 !Lots of code
 CALL p1 ($OPTIONAL ($PARAM (p), p ),
 $OPTIONAL ($PARAM (q), q ));
 !Lots of code
 END;










