Variables Variables

MOSES has two types of variables, global and local. The difference between the two is the extent of their lives. A global variable lives forever (as long as the database for a given root exists), while a local variable vanishes once the procedure which defined it ceases to exist. The scheme employed here is similar to that used elsewhere in that if one defines a local variable with the same name as a global one, then the global variable will be "over loaded" as long as the local variable is active. In other words, if one defines a local variable with the same name as a local variable in a higher macro or with the same name as a global variable, the previous one will not be used so long as the new local variable remains defined. The "dummy variables" in macros are a special case of local variables.

By a variable, we mean a string which is stored in the database and which may be referred to by its name. Before one may reference a global variable, it must be defined via a &SET command. The form of this command is:


     &SET, VAR, =, value

Notice that the equal sign must be followed by a space or comma before the value. All variables (including arguments) are processed as string replacements. In other words, the above command defines a string of characters. These characters will be replaced whenever the string %VAR is used in an input record. There are actually several ways of instructing MOSES to substitute a variable. In all cases, the variable must be referenced with a % as the beginning character. The next character may be a (, in which case, the reference must end with a ). If the ( is omitted, the reference can end with either a %, a comma or a blank. The only real reason to enclose the name in parentheses is that MOSES will honor one level of recursive use of variables.

For example:

     &SET DOG = 20
     &SET CAT = %DOG%*2000
     &SET COW = %DOG%A

or

     &SET COW = %(DOG)A
     &TYPE %COW%

or

     &TYPE %COW

or

     &TYPE %(COW)

will set variable DOG to 20, CAT to 20*2000 (i.e. 40000), COW to 20A, and will type 20A to the terminal. For the recursive use of variables, consider:

     &SET DOG1 = 20
     &SET DOG2 = 40
     &SET INTE = 1
     &SET ANS  = 30*%(DOG%(INTE))
     &TYPE %ANS

will result in 30*20 being written to the terminal. Here, the variable INTE will be evaluated first, and then the variable DOG1 will be substituted.

Often, one wishes to have variables which are local to a given macro. This can be accomplished by "typing" a set of variables to be local as follows:


     &LOCAL, LVAR(1), LVAR(2) = VAL, ......

When local variables are typed, their values are set to blank, unless one follows the variable name with a token of = and another token containing the value to which the variable is to be set. Once a local variable is typed, it may be reset via an &SET command and used as if it were a global variable.