Make your own free website on
2.3.1 Assignments
Assignments are clauses where the first token is a symbol and the
second token is the equal sign (=). This definition opens for some
curious effects, consider the following clauses:

a == b
     This is not a command, but an assignment of the expression =
     b to the variable a. Of course, the expression is illegal
     (=b) and will trigger a SYNTAX condition for syntax error
     {35}. TRL2 defines the operator == as consisting of two
     tokens. Thus, in the first of these examples, the second
     token is =, the third token is also =, while the fourth token
     is b.

3 = 5
     This is an assignment of the value 5 to the symbol 3, but
     since this is not a variable symbol, this is an illegal
     assignment, and will trigger the SYNTAX condition for syntax
     error {31}.

“hello” = foo
     This is not an invalid assignment, since the first token in
     the clause is not a symbol. Instead, this becomes a command.

arg =(foo) bar
     The fourth statement is a valid assignment, which will space-
     concatenate the two variable symbols foo and bar, and assign
     the result to the variable symbol arg. It is specifically not
     an ARG instruction, even though it might look like one. If
     you need an ARG instruction which template starts with an
     absolute indirect positional pattern, use the PARSE UPPER ARG
     instruction instead, or prepend a dot in front of the

An assignment can assign a value to a simple variable, a stem
variable or a compound variable. When assigning to a stem
variable, all possible variable symbols having that stem are
assigned the value.  Note specifically that this is not like
setting a default, it is a one time multiple assignment.

Example: Multiple assignment

The difference between REXX’s multiple assignment and a default
value can be seen from the following code:

     foo. = ‘bar’
     foo.1 = ‘baz’
     drop foo.1
     say foo.1        /* says “FOO.1” */

Here, the SAY instruction writes out FOO.1, not bar.  During the
DROP instruction, the variable FOO.1 regains its original,
uninitialized value FOO.1, not the value of its stem variable
FOO., i.e. bar, because stem assignments does not set up a

Example: Emulating a default value

If you want to set the compound variable to the value of its stem
variable, if the stem is initialized, then you may use the
following code:

     if (symbol(‘foo.’)) then
          foo.1 = foo.
          drop foo.1

In this example, the FOO.1 variable is set to the value of its
stem if the stem currently is assigned a value. Else, the FOO.1
variable is dropped.

However, this is probably not exactly the same, since the internal
storage of the computer is likely to store variables like FOO.2
and FOO.3 only implicitly (after all, it can not explicitly store
every compound having FOO. as stem). After the assignment of the
value of FOO. to FOO.1, the FOO.1 compound variable is likely to
be explicitly stored in the interpreter.

There is no way you can discover the difference, but the effects
are often that more memory is used, and some functionality that
dumps all variables may dump FOO.1 but not FOO.2 (which is
inconsistent). See section RexxVariablePool.

Example: Space considerations

Even more strange are the effects of the following short example:

     foo. = ‘bar’
     drop foo.1

Although apparently very simple, there is no way that an
interpreter can release all memory referring to FOO.1. After all,
FOO.1 has a different value than FOO.2, FOO.3, etc., so the
interpreter must store information that tells it that FOO.1 has
the uninitialized value.

These considerations may seem like nit-picking, but they will
matter if you drop lots of compound variables for a stem which has
previously received a value. Some programming idioms do this, so
be aware. If you can do without assigning to the stem variable,
then it is possible for the interpreter to regain all memory used
for that stem’s compound variables.