/sys$common/syshlp/HELPLIB.HLB  —  MACRO  /ALPHA  Directives  .MACRO  Examples
      Example 1
      This example shows how macro definitions and invocations may
      be nested. It also shows examples of the various forms of
      parameter passing.

        .MACRO OP1 A,B=R4,?C
        C:      ADDL R2, B, R3
        .MACRO OP'B
                TRAPB
        .ENDM OP'B
                ADDL A, R2, R3
                OP'B
                .MDELETE OP'B
        .ENDM OP1

      When OP1 is invoked "OP1 R0", the text expands to:

        33000$: ADDL R2, R4, R3
        .MACRO OPR4
                TRAPB
        .ENDM
                ADDL R0, R2, R3
                OPR4
                .MDELETE OPR4

      Processing this text will cause OPR4 to be expanded to TRAPB;
      the final text will be:

        33000$: ADDL R2, R4 R3
                ADDL R0, R2, R3
                TRAPB

      Example 2
      The following example shows macro redefinition:

        .MACRO INITIALIZE
           .MACRO INITIALIZE   ;Redefine to nothing
           .ENDM INITIALIZE
           X=0
           Y=1
           Z=-1
        .ENDM INITIALIZE

      Note that while the redefined version of the macro immediately
      supersedes the previous definition in any subsequent
      invocation, the invocation of the original definition expands
      to completion.
      Example 3
      This example shows a recursive macro:

        .MACRO FACTORIAL N
           .IF EQUAL <N>,0      ;Basis step; stop at zero
              F=1
           .ELSE
              FACTORIAL <N-1>
              F = F * <N>
           .ENDC
        .ENDM FACTORIAL
Close Help