/MACRO_SYNTAX_Variables

Explanation of KUIP macro variables.

Macro variables do not have to be declared. They become defined by an assignment statement,

name = expression

The right-hand side of the assignment can be an arithmetic expression, a string expression, or a garbage expression (see MACRO/SYNTAX/Expressions). The expression is evaluated and the result is stored as a string (even for arithmetic expressions).

A variable value can be used in other expressions or in command lines by enclosing the name in square brackets, [name]. If the name enclosed in brackets is not a macro variable then no substitution takes place.

/MACRO/SYNTAX/Variables/Numbered

Accessing macro arguments.

The EXEC command can pass arguments to a macro. The arguments are assigned to the numbered variables [1], [2], etc., in the order given in the EXEC command. The name of the macro, including the file specification, is assigned to [0].

A numbered variable cannot be redefined, i.e., an assignment such as "1 = foo" is illegal. See MACRO/SYNTAX/SHIFT.

/MACRO/SYNTAX/Variables/Special

Predefined special macro variables.

For each macro the following special variables are always defined:

[0] Fully qualified name of the macro. [#] Number of macro arguments [*] List of all macro arguments, separated by blanks [@] EXITM return code of the last macro called by the current one. The value is "0" if the last macro did not supply a return code or no macro has been called yet.

As for numbered variables these names cannot be used on the left-hand side of an assignment. The values or [#] and [*] are updated by the SHIFT statement.

/MACRO/SYNTAX/Variables/Indirection

Referencing a macro variable indirectly.

Macro variables can be referenced indirectly. If the variable [name] contains the name of another variable the construct

[%name]

is substituted by that other variable's value. For example, this is another way to traverse the list of macro arguments:

DO i=1,[#] arg = [%i] ... ENDDO

There is only one level of indirection, i.e., the name contained in "name" may not start with another "%".

/MACRO/SYNTAX/Variables/Global

Declaring a global variable.

EXTERN name ...

The variable names listed in the EXTERN statement are declared as global variables. If a name has not been defined with the GLOBAL/CREATE command, it is created implicitly and initialized to the empty string. The name list may contain wildcards, for example

EXTERN *

makes all defined global variables visible.

/MACRO/SYNTAX/Variables/READ

Reading a variable value from the keyboard.

READ name [ prompt ]

Variable values can be queried from the user during macro execution. The READ statement prompts for the variable value. If name is already defined the present value will be proposed as default.

/MACRO/SYNTAX/Variables/SHIFT

Manipulation numbered variables.

The only possible manipulation of numbered variables is provided by the SHIFT statement which copies [2] into [1], [3] into [2], etc., and discards the value of the last defined numbered variable. For example, the construct

WHILE [1] <> ' ' DO arg = [1] ... SHIFT ENDDO

allows to traverse the list of macro arguments.