Web 68 provides two kinds of macros:
Both macros may have any number of parameters (including none).
The definition of a macro consists of four or five parts:
@d
or @m
)
followed by at least one space
=
)
The text
@m identifier = Algol 68 textdefines a simple macro, where the identifier will be replaced by the Algol 68 text when tang produces its output.
The text
@m identifier (p1,…, pn) = Algol 68 textdefines a parametric macro, where the identifier plus the actual parameters (in a parameter pack) will be replaced by the Algol 68 text and where occurrences of the formal parameters pi in that Algol 68 text will be replaced by the corresponding actual argument.
The formal parameter pack looks just like the parameter pack of an Algol 68 routine. The formal parameters themselves can take the form of Algol 68 identifiers or mode or operator indicants and should be separated by commas as in an Algol 68 routine call. The macro body can contain any Algol 68 code, including calls of previously defined macros, but parentheses should be balanced. Note that ``previously'' in this case refers to previously in the Web 68 file. Any occurrence of the formal parameters in the text, as a lexical unit, will be replaced by the corresponding actual parameter when the macro is expanded. These two examples show a simple macro and a parametrised macro, both taken from tang:-
@m help status = 1 @m err print(msg)=(print nl; print out(msg); error(errors))and here is a declarative macro taken from the forms.w prelude:-
@d macro x raise window = PROC(DISPLAY,WINDOW)INT x raise window = ALIEN "XRAISEWINDOW" "#define XRAISEWINDOW(dpy,win) \" " XRaiseWindow((void *)dpy,win)";Because declarative macros can be only be called once, they usually do not have parameters.
It should be noted that macros have to be recognised during tang's first phase, so every macro must be defined before it is used. You should not call a macro recursively. Macros are expanded by tang in its second phase.
Macros are only operational for tang. weav simply regards them as Algol 68 code. However, the macro identifier will appear in the cross-reference index.
Sian Mountbatten 2012-01-05