pTAL Reference Manual (G06.24+, H06.09+, J06.03+)

Example 32 Assignment Statement Using DEFINE Macro Identifier
DEFINE cube (x) = ( x * x * x ) #;
INT result;
result := cube (3) '>>' 1;
! Expands to: (3 * 3 * 3) '>>' 1 = 27 '>>' 1 = 13
Example 33 Incrementing and Decrementing Utilities
DEFINE increment (x) = x := x + 1 #;
DEFINE decrement (y) = y := y - 1 #;
INT index := 0;
increment(index); ! Expands to: index := index + 1;
Example 34 Filling an Array With Zeros
DEFINE zero_array (array, length) =
BEGIN
array[0] := 0;
array[1] ':=' array FOR length - 1;
END #;
LITERAL len = 50;
INT buffer[0:len - 1];
zero_array (buffer, len); ! Fill buffer with zeros
Example 35 (page 102) displays a message, checks the condition code, and assigns an error if
one occurs.
Example 35 Checking a Condition Code
INT error;
INT file;
INT .buffer[0:50];
INT count_written;
INT i;
DEFINE emit (filenum, text, bytes, count, err) =
BEGIN
CALL WRITE (filenum, text, bytes, count);
IF < THEN
BEGIN
CALL FILEINFO (filenum, err);
! Process errors if any
END;
END #;
! Lots of code
IF i = 1 THEN
emit (file, buffer, 80, count_written, error);
102 LITERALs and DEFINEs