Stems
A stem is a symbol that contains just one period, which is the last character. It cannot start with a digit or a period.
These are stems:
FRED.
A.
<.A.B>. By default, the value of a stem is
the string that consists of the characters of its symbol (that is, translated to uppercase). If the
symbol has been assigned a value, it names a variable and its value is the value of that
variable.When a stem is used as the target of an assignment, all possible compound variables whose names begin with that stem receive the new value, whether they previously had a value or not. Following the assignment, a reference to any compound symbol with that stem returns the new value until another value is assigned to the stem, or to the individual variable.
For example:
hole. = "empty"
hole.9 = "full"
say hole.1 hole.mouse hole.9
/* says "empty empty full" */
Thus, you can give a whole collection of variables the same value. For example:
total. = 0
do forever
say "Enter an amount and a name:"
pull amount name
if datatype(amount)='CHAR' then leave
total.name = total.name + amount
endNote: You can always obtain the value that has been assigned to the whole collection of variables by
using the stem. However, this is not the same as using a compound variable whose derived name is the
same as the stem. For example:
total. = 0
null = ""
total.null = total.null + 5
say total. total.null /* says "0 5" */You can manipulate collections of variables, referred to by their stem, with the DROP
and PROCEDURE instructions.
DROP FRED. drops all variables with that stem (see
DROP), and PROCEDURE EXPOSE FRED. exposes all possible
variables with that stem (see PROCEDURE). Note:
- When the ARG, PARSE, or PULL instruction, or the VALUE built-in function, or the variable pool interface changes a variable, the effect is identical with an assignment. Anywhere a value can be assigned, using a stem sets an entire collection of variables.
- Because an expression can include the operator
=, and an instruction can consist purely of an expression (see Commands to External Environments), a possible ambiguity is resolved by the following rule: any clause that starts with a symbol and whose second token is (or starts with) an equal sign (=) is an assignment, rather than an expression (or a keyword instruction). This is not a restriction, because you can ensure the clause is processed as a command in several ways, such as by putting a null string before the first name, or by enclosing the first part of the expression in parentheses.Similarly, if you unintentionally use a REXX keyword as the variable name in an assignment, this should not cause confusion. For example, the following clause is an assignment, not an ADDRESS instruction:Address='10 Downing Street'; - You can use the SYMBOL function to test whether a symbol has been assigned a value (see SYMBOL). In addition, you can set SIGNAL ON NOVALUE to trap the use of any uninitialized variables (except when they are tails in compound variables; see Conditions and condition traps).