Kilowatt Software L.L.C.
Classic Rexx Tutorial
Language Level 4.00 (TRL-2)

# Symbolic variables

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.

1. Constant symbols
2. Simple variables
3. Compound variables
4. Compound stems

## Constant 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!

## Simple variables

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.

## Compound variables

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 ```    shows:   ISPRIME.X.Y   ISPRIME.1.7   not prime   prime   ISPRIME.1.7

## Compound stems

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 ```    shows:   not prime   prime   not prime anymore   ISPRIME.1.7

## Character case considerations

The character case within symbol names is insignificant. The following names are all equivalent.

 first_name First_Name FIRST_NAME color.red Color.Red COLOR.RED isprime. IsPrime. ISPRIME.

## A compound variable example

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 ```

Explanation:

• The words within a string are assigned to the variables by the getwords internal procedure.

• Before calling the procedure, the compound stem word. is assigned a default value -- the empty string.

• The compound stem variable, word., is exposed.

• The number of words is assigned to the word.0 variable.

• Words within the string are assigned to the variables word.1, word.2, etc.

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.

Kilowatt Software L.L.C. -- Classic Rexx Tutorial -- Back to top
Click here if you have any comments or questions regarding this tutorial

Last updated on: 11 Apr 2006