A compound symbol permits the substitution of variables within its name when you refer to it. A compound symbol contains at least one period and at least two other characters. It cannot start with a digit or a period, and if there is only one period in the compound symbol, it cannot be the last character.
taila='* ('
tailb=''
stem.taila=99
stem.tailb=stem.taila
say stem.tailb /* Displays: 99 */
/* But the following instruction would cause an error */
/* say stem.* ( */
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
a valid symbol.FRED.3
Array.I.J
AMESSY..One.2.
<.F.R.E.D>.<.A.B>
Before the symbol
is used (that is, at the time of reference), the language processor
substitutes the values of any simple symbols in the tail (I, J, and One in the examples), thus generating a new,
derived name. This derived name is then used just like a simple symbol.
That is, its value is by default the derived name, or (if it has been
used as the target of an assignment) its value is the value of the
variable named by the derived name.The substitution into the symbol that takes place 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 one time.
s0.s1.s2. --- .sn
is given by
d0.v1.v2. --- .vn
where d0 is the uppercase form of the symbol s0,
and v1 to vn are the values of the constant
or simple symbols s1 through sn. Any of the
symbols s1-sn can be null. The values v1-vn can also be null and can contain any characters
(in particular, lowercase characters are not translated to uppercase,
blanks are not removed, and periods have no special significance).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 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, effecting a form of associative memory (content addressable).
Implementation maximum: The length of a variable name, before and after substitution, cannot exceed 250 characters.