TAL Reference Manual

Standard Functions
TAL Reference Manual526371-001
14-34
Examples of the $OPTIONAL Function
2. This example shows that a called procedure cannot distinguish between a
parameter that is omitted conditionally and one that is omitted unconditionally:
PROC p1 (i) EXTENSIBLE;
INT i;
BEGIN
!Lots of code
END;
PROC p2;
BEGIN
INT n := 1;
CALL p1 ($OPTIONAL (n < 0, n) ); !These two calls are
CALL p1 ( ); ! indistinguishable.
END;
3. This example shows how you can conditionally pass or not pass a parameter and a
parameter pair. When P2 calls P1, S:I is passed because I equals 1, which is less
than 9. 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;
4. You can use $OPTIONAL 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;