REDUCE

5.1 Assignment Statements

These statements have the syntax

\(\langle \)assignment statement\(\rangle \) \(\longrightarrow \) \(\langle \)expression\(\rangle \) := \(\langle \)expression\(\rangle \)

The \(\langle \)expression\(\rangle \) on the left side is normally the name of a variable, an operator symbol with its list of arguments filled in, or an array name with the proper number of integer subscript values within the array bounds. For example:

a1 := b + c
h(l,m) := x-2*y    (where h is an operator)
k(3,5) := x-2*y (where k is a 2-dim. array)

More general assignments such as a+b := c are also allowed. The effect 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 simplification 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:

\(\langle \)expression\(\rangle \) := := \(\langle \)expression\(\rangle \) := \(\langle \)expression\(\rangle \)

In this form, each \(\langle \)expression\(\rangle \) but the last is set to the value of the last \(\langle \)expression\(\rangle \). 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(\(\langle \)expression\(\rangle \),\(\langle \)expression\(\rangle \));

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(\(\langle \)expression\(\rangle \));

For example, the statement

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

clears the value of A23.


Hosted by Download REDUCE Powered by MathJax