6. Assignment
Assignment transfers data from one container to another.
The equal sign ('=') is the symbol for assignment. The value of the operand on the right of the equal sign is transferred to the operand on the left. (Eventually, both operands will be weakly-restricted Datalanguage expressions, which may evaluate to sets as well as to single containers. Now, the left must be a container name, the right may be a container name or a constant.)
Assignment is defined for all types of containers. When the containers are aggregates, their elements are paired and data is transferred between paired elements. Elements of the target container that do not pair with some source element are handled with a default operation (currently they are filled with blanks).
The operands of an assignment must have descriptions that match. The idea of matching is that the descriptions must be similar enough so that it is obvious how to map one into the other.
6.1 Conditions for legitimate assignment
Assignment must reference objects, not sets. An object is:
(a) an outermost container, or
(b) a constant, or
(c) in the body of a FOR-loop, either
(c1) a member of a set defined by a FOR-OPERAND, or
(c2) a container which occurs once in such a member
In the case of a reference of type (c1), the object referenced is taken to be the current member. In the case of (c2), the object referenced is that which occurs in the current member. This is explained further in section 7.
The left operand of an assignment is subject to further restriction. If it is an outermost container, it must be open in either WRITE- or APPEND-mode. If it is not an outermost container, then the reference is of type (c), which means that some FOR-operand has established a context in which the assign-operand is an object. The FOR-operand which establishes this context must be the output-operand of the FOR.
When the assign-operand is an outermost container, it must be open. Such an operand must be referenced by its simple container ident(***), not its directory pathname.
In the body of a loop nested in one or more other loops, assignments are further restricted, due to a 0/9 implementation problem. See section 7.2 for details.
Finally, the descriptions of the operands must match. If one is a constant, then the other must be a STRING(***). If both are containers, then in the expression:
A = B;
the descriptions of containers A and B match if:
- A and B have the same type
- If A and B are LISTs, then they have equal numbers of LIST-members, or else A is an outermost-LIST.
- If A and B are aggregates, then at least one container immediately enclosed in A matches, and has the same ident as, one container immediately enclosed in B.
6.2 Result of assignment
If the operands are STRINGs, then the value of B, left-justified, replaces the value of A. If B is longer than A, the value is truncated. If B is shorter than A, then A is filled on the right with blanks as necessary.
If the operands are STRUCTs, then assignment is defined in terms of the STRUCT members. If a member of A, mA, matches and has the same name as a member of B, mB, then mB is assigned to mA. If no such mB exists, then mA is filled with blanks.
If the operands are LISTs, the result depends on several factors. First, notice that the descriptions of the LIST-members must match; otherwise the assignment would not be legitimate by the matching rules of 6.1.
If A is an outermost-LIST, then it can be in either of two modes: WRITE or APPEND. If A is in WRITE-mode, its previous contents are first discarded; it is then handled as though it were in APPEND-mode.
If A is not an outermost-LIST, then it is always effectively in WRITE-mode.
After taking the mode of A into account, as described above, the procedure is:
for each member of LIST B
(a) add a new member to the end of A
(b) assign the current number of B to the new member of A
6.3 Deletion of Data Through Assignment
If A is an outermost container in WRITE-mode, and B is a container with description that matches A, and if B contains no data, then A=B has the effect of deleting all data from A. Note that if A is in APPEND-mode in these circumstances, then A=B is a no-operation (i.e., has no effect).