1.13. Assignments and Symbols
A variable is an object whose value can change during the running of a Rexx program. The process of changing the value of a variable is called assigning a new value to it. The value of a variable is a single object. Note that an object can be composed of other objects, such as an array or directory object.
You can assign a new value to a variable with the ARG, PARSE, PULL, or USE instructions, the VALUE built-in function, or the but the most common way of changing the value of a variable is the assignment instruction itself. Any clause in the form
symbol= expression;
is taken to be an assignment. The result of expression becomes the new value of the variable named by the symbol to the left of the equal sign.
Example:
/* Next line gives FRED the value "Frederic" */
Fred="Frederic"
The symbol naming the variable cannot begin with a digit (0
-9
) or a period.
You can use a symbol in an expression even if you have not assigned a value to it, because a symbol has a defined value at all times. A variable to which you have not assigned
a value is
uninitialized. Its value is the characters of the symbol itself, translated to uppercase (that is, lowercase
a
-
z
to uppercase
A
-
Z
). However, if it is a compound symbol (described in
Section 1.13.5, “Compound Symbols”), its value is the derived name of the symbol.
Example 1.20. Derived symbol names
/* If Freda has not yet been assigned a value, */
/* then next line gives FRED the value "FREDA" */
Fred=Freda
The meaning of a symbol in Rexx varies according to its context. As a term in an expression, a symbol belongs to one of the following groups: constant symbols, simple symbols, compound symbols, environment symbols, and stems. Constant symbols cannot be assigned new values. You can use simple symbols for variables where the name corresponds to a single value. You can use compound symbols and stems for more complex collections of variables although the collection classes might be preferable in many cases. See
Section 5.3.2, “The Collection Class”.
1.13.1. Extended Assignments
The character sequences +=, -=, *= /=, %=, //=, ||=, &=, |=, and &&=
can be used to create extended assignment instructions. An extended assignment combines a non-prefix operator with an assignment where the term on the left side of the assignment is also used as the left term of the operator. For example,
a += 1
is exactly equivalent to the instruction
a = a + 1
Extended assignments are processed identically to the longer form of the instruction.