SET assigns values to variables or to a selected portion of a variable.
The format of the SET command is:
S[ET][:tvexpr] glvn|$EXTRACT()|$PIECE()|(glvn[,...])=expr[,...]
The optional truth-valued expression immediately following the command is a command postconditional that controls whether or not GT.M executes the command.
A subscripted or unsubscripted local or global variable name on the left of the equal-sign (=) specifies a variable in which to store the expression found on the right side of the equal-sign; the variable need not exist prior to the SET; if the variable exists prior to the SET, the SET replaces its old value.
During a SET, GT.M evaluates the right side of the equal sign before the left; this is an exception to the left-to-right order of evaluation in GT.M and means that GT.M maintains the naked indicator using the expression on the right-hand side of the equal sign (=) before setting the variable.
When the portion of the argument to the left of the equal-sign is in the form of a list of variables enclosed in parentheses, SET assigns the value of the expression on the right of the equal sign to all the variables.
When the portion of the argument to the left of the equal sign is in the form of a $PIECE function, SET replaces the specified piece or pieces of the variable (specified as the first argument to the $PIECE() form) with the value of the expression on the right side of the equal-sign; if the variable did not exist prior to the SET or does not currently contain the pieces identified by the optional third and fourth arguments to the $PIECE() form, SET adds sufficient leading delimiters, as specified by the second argument to the $PIECE form, to make the assignment fit the $PIECE() form. Note that if the fourth argument exceeds the third argument, the target glvn is not changed and the naked indicator is also not modifed.
When the portion of the argument to the left of the equal sign is in the form of a $EXTRACT function, SET replaces the specified character or characters of the variable (specified as the first argument to the $EXTRACT() form) with the value of the expression on the right side of the equal-sign; if the variable did not exist prior to the SET or does not contain the characters identified by the optional second and third arguments to the $EXTRACT() form, SET adds sufficient leading spaces to make the assignment fit the $EXTRACT() form. Note that if the third argument exceeds the second argument, the target glvn is not changed and the naked indicator is also not modifed.
The left-hand side of the equal-sign may also contain any of the following Intrinsic Special Variables:
$ECODE
$ETRAP
$X
$Y
$ZCOMPILE
$ZDIRECTORY
$ZERROR
$ZGBLDIR
$ZINTERRUPT
$ZMAXTPTIME
$ZPROMPT
$ZROUTINES
$ZSOURCE
$ZSTATUS
$ZSTEP
$ZTRAP
$ZYERROR
An indirection operator and an expression atom evaluating to a list of one or more SET arguments form a legal argument for a SET.
Because GT.M does not require predeclaration or typing of variables, a SET withproper syntax always succeeds regardless of the prior state or value of the variable, as long as GT.M can evaluate the expression to the right of the equal sign (=).
For more information on syntax for $PIECE(), refer to the "Functions" chapter in this manual.