perm filename MACLIE.WRU[NEW,AIL] blob
sn#408203 filedate 1979-01-08 generic text, type T, neo UTF8
NOVEMBER 28,1973
The following is a set of hints and aids in debugging programs with macros.
Unless otherwise stated array brackets are the macro body delimiters.
If you encounter other strange quirks, do not hesitate to inform HJS
about them so others will benefit from your experience.
1. IFC and friends will not trigger at the point of macro definition, in
a macro actual parameter list, or inside a string constant.
DEFINE FOO = [IFC A THENC B ELSEC D ENDC];
which is not the same as
DEFINE FOO = IFC A THENC [B] ELSEC [D] ENDC;
DEFINE BAZ(A) = [OUTSTR("A");];
BAZ(IFC B THENC C ELSEC D ENDC)
will result in the following string typed on your terminal:
IFC B THENC C ELSEC D ENDC
STRING A;
A←"IFC WILL NOT TRIGGER HERE";
2. Macros will not be expanded in strings, but macro formal parameters
will be expanded when they occur in strings within macro bodies as seen
in the second example of 1. above.
DEFINE FOO = [BAZ];
OUTSTR("FOO");
which will type out the string FOO on your terminal rather than BAZ.
3. Caution should be employed when using letters (specifically ↑P↑Q) as
delimiters. This may lead to problems when defining macros within macros.
DEFINE MAC(A) "↑P↑Q" = ↑PREDEFINE FOO =↑PA↑Q;↑Q;
A inside the macro body of MAC, A will not be recognized as a formal
since the scanner has scanned ↑PA↑Q as an identifier by virtue of ↑P↑Q
being internally represented as letters so that some of YOU could
define them to mean BEGIN and END respectively (also ↑P as COMMENT).
More justification for this feature is seen by the following example:
DEFINE MAC(ABC) "AC" = A V←ABC; C;
We want ABC in the text to be the parameter and not B if we were to
ignore the macro delimiters.
4. When scanning lists of actual parameters, macros are not expanded.
DEFINE FOO = [A,B];
MAC(FOO) will not have the result MAC(A,B) however,
DEFINE FOO = [(A,B)]
followed by MAC FOO will have the same effect as MAC(A,B)
The same reasoning holds for parameter lists to FORLC.
DEFINE FOO = [A,B,C];
FORLC I = (FOO) DOC [OUTSTR("I");] ENDC
will result in FOO typed out on your terminal.
DEFINE FOO = [(A,B,C)];
FORLC I = FOO DOC [OUTSTR("I");] ENDC
will have the desired result ABC typed out on your terminal.
January 22,1974
1. In order to take advantage of the nestable character feature in the
parameters to a macro call, one must be in REQUIRE DELIMITERS mode.
Otherwise scanning will break upon seeing a comma or a right parenthesis.
BEGIN
DEFINE FOO(A) = "A";
INTEGER ARRAY ABC[1:10,1:10];
FOO(ABC[1,2])←3;
END;
This is identical to:
BEGIN
INTEGER ARRAY ABC[1:10,1:10];
ABC[1←3; comment this is an illegal statement;
END;
However, if the original program had included a REQUIRE DELIMITERS statement
prior to the macro call, as below, then the desired effect would have resulted -
i.e. ABC[1,2]←3 .
BEGIN
REQUIRE "{}%$" DELIMITERS;
DEFINE FOO(A) = {A};
INTEGER ARRAY ABC[1:10,1:10];
FOO(ABC[1,2])←3;
END;