Macro Arguments (DEFINE-!ENDDEFINE command)
The macro definition can include macro arguments,
which can be assigned specific values in the macro call. There are
two types of arguments: keyword and positional. Keyword arguments
are assigned names in the macro definition; in the macro call, they
are identified by name. Positional arguments are defined after the
keyword !POSITIONAL in the macro
definition; in the macro call, they are identified by their relative
position within the macro definition.
- There is no limit to the number of arguments that can be specified in a macro.
- All arguments are specified in parentheses and must be separated by slashes.
- If both keyword and positional arguments are defined in the same definition, the positional arguments must be defined, used in the macro body, and invoked in the macro call before the keyword arguments.
Example
* A keyword argument.
DEFINE macname (arg1 = !TOKENS(1))
frequencies variables = !arg1.
!ENDDEFINE.
macname arg1 = V1.
- The macro definition defines
macnameas the macro name andarg1as the argument. The argumentarg1has one token and can be assigned any value in the macro call. - The macro call expands the
macnamemacro. The argument is identified by its name,arg1, and is assigned the valueV1.V1is substituted wherever!arg1appears in the macro body. The macro body in this example is theFREQUENCIEScommand.
Example
* A positional argument.
DEFINE macname (!POSITIONAL !TOKENS(1)
/!POSITIONAL !TOKENS(2))
frequencies variables = !1 !2.
!ENDDEFINE.
macname V1 V2 V3.
- The macro definition defines
macnameas the macro name with two positional arguments. The first argument has one token and the second argument has two tokens. The tokens can be assigned any values in the macro call. - The macro call expands the
macnamemacro. The arguments are identified by their positions.V1is substituted for!1wherever!1appears in the macro body.V2andV3are substituted for!2wherever!2appears in the macro body. The macro body in this example is theFREQUENCIEScommand.