next up previous contents index
Next: 4.3.1.3 Pre-defined Macros Up: 4.3.1 Macros Previous: 4.3.1.1 An Example   Contents   Index

4.3.1.2 Parameters

A macro may carry 1 or more parameters. In the left-hand side of a macro definition, the formal parameters are specified in a way similar to the parameters of a Python function. Default values can be given to all or some of the parameters. If only part of the parameters are given default values, the parameters that do not have default values must be specified before the parameters that have default values. For example, the following specifications of the left-hand sides of macro definitions are valid:

On the right-hand side, parameters are referred to with their name between square brackets. For example, parameters p1, p2 and p3 are referred to with [p1], [p2] and [p3], respectively.

To use a macro, all the parameters must have their values. Values must be explicitly assigned to the parameters that do not have default values. 0 or more ending parameters that have default values can be omitted. For example, to use macro my_macro(p1, p2, p3="hello"), the following statements are valid:

In all these use cases, the actual values of p1, p2 and p3 are 1, 2 and "hello", respectively.

Macros can be used as parameters of other macros.

Brackets for parameters cannot be omitted even if in the definition of a macro, all the parameters have default values, or there is no parameter specified between the brackets. For example, to use my_macro(p="hello") = ... or my_macro() = ..., the user must include the brackets ([my_macro()]). However, to use macro my_macro = ..., simply write [my_macro].


next up previous contents index
Next: 4.3.1.3 Pre-defined Macros Up: 4.3.1 Macros Previous: 4.3.1.1 An Example   Contents   Index
Thomas Huining Feng 2004-04-28