Kilowatt Software's
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.

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.

Character case considerations

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

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.

Explanation:

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's -- Classic Rexx Tutorial -- Back to top
Click here if you have any comments or questions regarding this tutorial

Last updated on: 12 Aug 2002