System Debug Reference Manual (32650-90888)

Chapter 6 209
System Debug Command Specifications M-X
MAC[RO]
to return the functional result of twice the input parameter. Note how the macro is used as
a function, as an operand in an expression.
%nmdat > mac triple (p1:INT) { return p1*3 }
%nmdat > wl triple(2)
$6
%nmdat > wl triple (double (1+2))
$12
Macro function triple is similar to macro function double defined above. Note that
macros (used as functions) can be nested within expressions.
$nmdebug > { macro factorial=1 (n)
{$1} multi > machelp = 'Returns the factorial for parameter "n"'
{$1} multi > mackey = 'FACTORIAL UTILITY ARITH TEST'
{$1} multi > macver = 'A.01.00'
{$1} multi > { if n <= 0
{$2} multi > then return
{$2} multi > else if n > 10
{$2} multi > then { wl "TOO BIG"; return}
{$2} multi > else return n * factorial(n-1)
{$2} multi > }
{$1} multi > }
$nmdebug > wl factorial(0)
$1
$nmdebug > wl factorial(1)
$1
$nmdebug > wl factorial(2)
$2
$nmdebug > wl factorial(3)
$6
$nmdebug > wl factorial(123)
TOO BIG
$1
This example defines a macro function named factorial that has a default return value
of 1. A help string, keyword string, and version string are included in the macro definition.
Note that the macro definition was preceded by a left curly brace in order to enter
multi-line mode
. This allowed the options to be specified on separate lines, before the left
curly brace for the macro body.
This macro calls itself recursively, but protects against runaway recursion by testing the
input parameter against an upper limit of ten.
Discussion - Macro Parameters
Assume that the following macro is defined.
$nmdat > { macro double( num=$123, loud=TRUE)
{$1} multi > { if loud
{$2} multi > then wl 'the double of ', num, ' = ', num*2;
{$2} multi > return num*2}
{$1} multi > }