next up previous contents index
Next: Physical Elements and Markers Up: Control Statements Previous: WHILE: Repeated Execution   Contents   Index


MACRO: Macro Statements (Subroutines)

Subroutine-like commands can be defined by a MACRO statement. It allows usages similar to C language function call statements. A macro is defined by one of the following statements:

name(formals): MACRO { token-list }
name(): MACRO { token-list }
A macro may have formal arguments, which will be replaced by actual arguments at execution time. An empty formals list is denoted by (). Otherwise the formals consist of one or more names, separated by commas. The token-list consists of input tokens (strings, names, numbers, delimiters etc.) and is stored unchanged in the definition.

A macro is executed by one of the statements:


name(actuals);
name();
Each actual consists of a set of tokens which replaces all occurrences of the corresponding formal name. The actuals are separated by commas. Example:

// macro definitions:
SHOWIT(X): MACRO {
   SHOW, NAME = X;
}
DOIT(): MACRO {
   DYNAMIC,LINE=RING,FILE="DYNAMIC.OUT";
}

// macro calls:
SHOWIT(PI);
DOIT();



MAD User Guide, http://wwwslap.cern.ch/mad/