Rexx symbols are sequences of numbers, letters, and the characters: . ! ? and _. Numeric symbols can be expressed in scientific notation as well; such as, 1.23e+7, or 4.56E-3. Symbols are assigned values by using the assignment, PARSE, ARG, and PULL instructions. The DROP instruction is used to eliminate the values associated with symbols.
There are four types of symbols.
These are numeric values; such as, 007, .3, 1234.56, -1, 1.23e+7, and 4.56E-3. The value of these symbols is their numeric value. Very large values will be converted during arithmetic operations as per the prevailing numeric DIGITS setting. For example, although 1234567891011121314 is a Rexx constant symbol, it will be considered to be 1.23456789E+18 when the digits is set to 9. Yet, if the digits setting were 19 or more then 1234567891011121314 would have its true value, and would be considered to be a whole number!
A simple variable is a symbol name that does not contain any periods, and does not start with a digit. When referenced the symbol is replaced with its value. An example of a simple variable is: first_name. If the symbol does not have an assigned value, then it is replaced by its name in upper case: FIRST_NAME.
A compound variable is a symbol name that does not start with a digit or period, but contains one or more periods. In addition, the last character is not a period, when the symbol contains only one period. An example of a compound variable is: isPrime.X.Y. The leading portion of the compound variable, up to and including the first period, is the associated stem of the compound variable. The portion of the variable name that follows the first period is called the tail. For the name isPrime.X.Y, the stem is ISPRIME. and the tail is X.Y. The compound variable's derived name is created by replacing each simple symbol in the tail with its value. Thus, if X is 1 and Y is 7, then the derived name of isPrime.X.Y would be ISPRIME.1.7. When referenced the compound variable is replaced with its value, if one is assigned. If the compound variable does not have an assigned value, then it is replaced by the value of the stem if the stem has an assigned value. Otherwise, the value is replaced by the derived name.
When a compound variable is dropped then references to the compound variable will be replaced by the variable's derived name, EVEN IF the compound stem has a value.
An example is helpful.
say isPrime.X.Y x = 1 y = 7 say isPrime.X.Y isPrime. = 'not prime' say isPrime.X.Y isPrime.1.7 = 'prime' say isPrime.X.Y drop isPrime.X.Y say isPrime.X.Y
A compound stem is a symbol name that does not start with a digit or period, but contains a single period which is the last character in the symbol name. An example of a compound stem is: isPrime.. When referenced the compound stem is replaced with its value. If the symbol does not have an assigned value, then it is replaced by its name in upper case: ISPRIME..
When a compound stem is assigned a value, all compound variables that begin with the stem are assigned the value as well.
When a compound stem is dropped the compound stem variable, and all compound variables that begin with the stem are unassigned.
Again an example is helpful.
isPrime. = 'not prime' say isPrime.X.Y isPrime.1.7 = 'prime' say isPrime.X.Y isPrime. = 'not prime anymore' say isPrime.X.Y drop isPrime. say isPrime.X.Y
not prime anymore
The character case within symbol names is insignificant. The following names are all equivalent.
The following is an example that shows how a sequence of words can be assigned to a set of compound variables.
word. = '' /* default value */ call getwords 'abra ca dabra' if word.0 > 0 then say value( 'word.' || random( 1, word.0 ) ) /* get a random word from the list */ return getwords : procedure expose word. s = arg(1) word.0 = words( s ) do i=1 for words( s ) word.i = word( s, i ) end return word.0
After calling the procedure, the main program can reference individual words by index; i.e. word.3. In the example the value built-in function was used to dynamically reference an arbitrary word within the set of words.