Assignment Statements
Date: 2020-10-07 18:10:00

Up | Next | Tail

### 5.1 Assignment Statements

These statements have the syntax

⟨assignment statement⟩ ::= ⟨expression⟩:=⟨expression⟩

The ⟨expression⟩ on the left side is normally the name of a variable, an operator symbol with its list of arguments ﬁlled in, or an array name with the proper number of integer subscript values within the array bounds. For example:

More general assignments such as a+b := c are also allowed. The eﬀect of these is explained in Section 11.2.5.

An assignment statement causes the expression on the right-hand-side to be evaluated. If the left-hand-side is a variable, the value of the right-hand-side is assigned to that unevaluated variable. If the left-hand-side is an operator or array expression, the arguments of that operator or array are evaluated, but no other simpliﬁcation done. The evaluated right-hand-side is then assigned to the resulting expression. For example, if a is a single-dimensional array, a(1+1) := b assigns the value b to the array element a(2).

If a semicolon is used as the terminator when an assignment is issued as a command (i.e. not as a part of a group statement or procedure or other similar construct), the left-hand side symbol of the assignment statement is printed out, followed by a “:=”, followed by the value of the expression on the right.

It is also possible to write a multiple assignment statement:

⟨expression⟩:=…:=⟨expression⟩:=⟨expression⟩

In this form, each ⟨expression⟩ but the last is set to the value of the last ⟨expression⟩. If a semicolon is used as a terminator, each expression except the last is printed followed by a “:=” ending with the value of the last expression.

#### 5.1.1 Set and Unset Statements

In some cases, it is desirable to perform an assignment in which both the left- and right-hand sides of an assignment are evaluated. In this case, the SET statement can be used with the syntax:

SET(⟨expression⟩,⟨expression⟩);

For example, the statements

j := 23;
set(mkid(a,j),x);

assigns the value X to A23.

To remove a value from such a variable, the UNSET statement can be used with the syntax:

UNSET(⟨expression⟩);

For example, the statement

j := 23;
unset(mkid(a,j));

clears the value of A23.

Up | Next | Front