Product SiteDocumentation Site

1.13.5. Compound Symbols

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, which are parts of the name (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, its 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
s0.s1.s2. --- .sn
is given by
d0.v1.v2. --- .vn
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).

1.13.5.1. Evaluated Compound Variables

The value of a stem variable is always a Stem object (see Section 5.3.15, “The Stem Class” for details). A Stem object is a type of collection that supports the [] and []= methods used by other collection classes. The [] method provides an alternate means of accessing compound variables that also allows embedded subexpressions.
Tails for compound variables are normally specified by symbols separated by periods. An alternative is to specify the tail as a bracketed list of expressions separated by commas. The expressions are evaluated to character strings. These are concatenated with intervening periods and the resulting string is used as tail. This notation can be used in assignments to compound variables as well as when referencing them. Examples:

Example 1.32. Evaluated compound variables

a.[1+2,3+4]=17      -- assigns A.3.7
Say a.3.7           -- => 17
v1='1+2'
v2='3+4'
a.v1.v2=18          -- tail used: '1+2.3+4'
Say a.['1+2','3+4'] -- => 18
Parse Value '1 2 3' With . a.[1,1+1] .
Say a.1.2           -- => 2