A
compound symbol
contains at least one period and two other characters.
It cannot start with a digit or a period, and if there is only one period
it cannot be the last character.
The name begins with a stem (that
part of the symbol up to and including the first period) and is followed by
a tail consisting of one or more name parts (delimited by periods)
that are constant
symbols, simple symbols, or null. Note that you cannot use constant symbols
with embedded signs (for example, 12.3E+5) after a stem; in this case the
whole symbol would not be valid.
These are compound symbols:
Example 1.30. Compound symbols
FRED.3
Array.I.J
AMESSY..One.2.
Before the
symbol is used, that is, at the time of reference, the language processor
substitutes in the compound symbol the character string values of any simple
symbols in the tail (
I,
J, and
One in the
examples), thus generating a new, derived tail. The value of a compound symbol
is, by default, it's the name of the Stem object associated with the stem variable
concatenated to the
derived tail or, if it has been used
as the target of an assignment, the value of Stem element named by the derived
tail.
The substitution in the symbol permits arbitrary indexing (subscripting)
of collections of variables that have a common stem. Note that the values
substituted can contain
any characters (including
periods and blanks). Substitution is done only once.
More formally, the derived name of a compound variable that is referenced
by the symbol
where
d0 is the name of the Stem
object associated with the stem variable
s0 and
v1 to
vn
are the values of the constant or simple symbols
s1 through
sn.
Any of the symbols
s1 to
sn can be null. The values
v1 to
vn
can also be null and can contain
any characters (including periods).
Lowercase characters are not translated to uppercase,
blanks are not removed, and periods have no special significance. There is
no limit on the length of the evaluated name.
Some examples of simple and compound symbols follow in the form of a small
extract from a Rexx program:
Example 1.31. Compound symbols
a=3 /* assigns "3" to the variable A */
z=4 /* "4" to Z */
c="Fred" /* "Fred" to C */
a.z="Fred" /* "Fred" to A.4 */
a.fred=5 /* "5" to A.FRED */
a.c="Bill" /* "Bill" to A.Fred */
c.c=a.fred /* "5" to C.Fred */
y.a.z="Annie" /* "Annie" to Y.3.4 */
say a z c a.a a.z a.c c.a a.fred y.a.4
/* displays the string: */
/* "3 4 Fred A.3 Fred Bill C.3 5 Annie" */
You can use compound symbols to set up arrays and lists of variables in
which the subscript is not necessarily numeric, thus offering a great scope
for the creative programmer. A useful application is to set up an array in
which the subscripts are taken from the value of one or more variables,
producing a form of associative memory (content-addressable).