A define invocation causes a define identifier to be replaced by the text associated with the define identifier.
<define invocation>
──<define identifier>─┬────────────────────┬───────────────────────────┤
└─<actual text part>─┘
<actual text part>
┌◄────── , ─────┐ ──┬─ ( ─┴─<actual text>─┴─ ) ─┬────────────────────────────────────────┤ │ ┌◄────── , ─────┐ │ └─ [ ─┴─<actual text>─┴─ ] ─┘
The parentheses and the brackets have identical meanings. These symbols are used when a parametric define is invoked.
Program text that cannot contain mismatched or unmatched parentheses, brackets, or quotation marks, or any comma outside of these bracketing symbols.
The invocation of a parametric define causes the actual text to be substituted into the positions in the text designated by the proper formal symbol.
The actual text need not be simple. As an example, assume you are using the following DEFINE declaration:
DEFINE FORJ(A,B,C) = FOR J:= A STEP B UNTIL C #
For this declaration, the following applies:
|
Define Invocation |
Expands to |
|
FORJ(0,B*3,MAX(X,Y,Z)) |
FOR J:= 0 STEP B*3 UNTIL MAX(X,Y,Z) |
The actual text can be empty in a define invocation. In this case, all occurrences of the corresponding formal symbol in the text are replaced by no text. For example, assume you are using the following DEFINE declaration:
DEFINE F(M, N) = M + N #
For this declaration, the following applies:
|
Define Invocation |
Expands to |
Syntactically Correct? |
|
R := F(, 1); |
R := +1; |
Yes |
|
R :=F(2,); |
R :=2+; |
No |
A define identifier cannot be invoked as a part, rather than the whole, of a language component such as a string literal or a number. For example, assume you are using the following declarations:
EBCDIC STRING S; DEFINE EBCDIC_STR = 8 #;
For these declarations, the following two statements are not interpreted by the compiler to be equivalent:
|
Statement |
Syntactically Correct? |
|
S : = EBCDIC_STR"ABC"; |
No |
|
S := 8"ABC"; |
Yes |
The invocation of define EBCDIC_STR is interpreted by the compiler as a whole language component, specifically a number, and not as an EBCDIC code preceding a quoted EBCDIC string. Thus, it appears that a number is being assigned to a string variable, which is illegal, and the compiler flags the statement with a syntax error.
As a further example, assume you are using the following declarations:
REAL R; DEFINE ITEM = 15 #;
For these declarations, the following applies:
|
Statement |
Legal? |
|
R := ITEM; |
Yes |
|
R := ITEM.30; |
No, because it is equal to R := (15).30;, which is illegal. |
In the following instances, the appearance of a define identifier does not cause the define to be expanded:
-
Defines are not expanded in an end remark, a comment remark, or an escape remark.
-
Defines are not expanded within quoted strings. For example, assume you are using the following declaration:
DEFINE ONE = THE FIRST #;
For this declaration, the string ONE WEEK is not equivalent to the string THE FIRST WEEK.
-
Defines are not expanded within identifiers. For example, assume you are using the following declaration:
DEFINE A = PREFIX #;
For this declaration, the identifiers A_B and ABC are not expanded to PREFIX_B and PREFIXBC.
-
Define identifiers are not always expanded when they occur in declarations. If the define identifier occurs in a position where an identifier can appear, the define identifier is not expanded. If the define identifier occurs in a position where an identifier is not expected, the define identifier is expanded. The following examples illustrate this rule:
DEFINE A = ARRAY #; A B[0:10]; % A is expanded. REAL A B[0:10]; % A can be interpreted as an identifier % in a REAL declaration. A is not % expanded. A syntax error results. EBCDIC A B[0:10]; % A is expanded.DEFINE THE_PARAMS = A_PROCEDURE, B, C#,%THE_PARAMS is not expanded THE_CALL (THE_PARAMS, D) = %when a reference to THE_CALL BEGIN %is made; thus, THE_CALL only A_PROCEDURE (D); %has two formal parameters, not END#; %four. The following receives a PROCEDURE A_PROCEDURE (Z); ... %syntax error indicating that the END; % of A_PROCEDURE %compiler expected a right %parenthesis after the second %parameter: % THE_CALL (P, Q, R, S); -
A define identifier is not expanded either in the format part of a FORMAT declaration or in the editing specifications of a READ statement or WRITE statement. Furthermore, if a FORMAT declaration or editing specifications are located within the text of a parametric define, they cannot reference the formal symbols of that define.
-
A define identifier is not expanded when used in place of any syntactic element of an EXPORT declaration.
-
A define identifier is not expanded when used in place of a file or task attribute mnemonic. Refer to the File Attributes Programming Reference Manual for file attribute mnemonics and the Work Flow Language (WFL) Programming Reference Manual for task attribute mnemonics.
In the following example, the define identifiers are not expanded in the FILE declaration or in the VALUE function:
DEFINE NEVERUSED = NEWTASK #,
PRINTER = REMOTE #;
FILE F(KIND = PRINTER); % INTERPRETED AS PRINTER,
% NOT REMOTE
T.STATUS := VALUE(NEVERUSED); % INTERPRETED AS NEVERUSED,
% NOT NEWTASKIf the ALGOL compiler encounters a syntax error while compiling the combination of the text, actual text part, and formal symbol part at the occurrence of a define invocation, some or all of the expanded define is given along with the appropriate error message.
To avoid problems with expanding a define, particularly when an expression is passed in as actual text, enclose in parentheses each occurrence of a formal symbol in the text of a parametric define. For example, consider the following program:
BEGIN
BOOLEAN BOOL;
DEFINE
LOGIC1(A,B) = (A AND B) #,
LOGIC2(A,B) = ((A) AND (B)) #;
BOOL := LOGIC1(TRUE OR TRUE, FALSE); % INVOCATION OF LOGIC1
BOOL := LOGIC2(TRUE OR TRUE, FALSE); % INVOCATION OF LOGIC2
END.The assignment of a value to BOOL differs, depending on whether you invoke LOGIC1 or LOGIC2, as shown in the following table:
|
Invocation |
Evaluates As |
Value Assigned to BOOL |
|
LOGIC1 |
BOOL := TRUE OR (TRUE AND FALSE); |
TRUE |
|
LOGIC2 |
BOOL := (TRUE OR TRUE) AND (FALSE); |
FALSE |
Passing an updating expression to a parametric define should be done cautiously. Multiple uses of the corresponding formal symbol cause multiple updates. For example, assume you are using the following DEFINE declaration:
DEFINE Q(E) = E + 2 * E #
For this declaration, the following applies:
|
Define Invocation |
Expands to |
|
Q (X := X + 1) |
X := X + 1 + 2 * X := X + 1 |

