assign INDEX

:= _ _ _ ASSIGN _ _ _ _ _ _ _ _ _ _ _ _ operator

The := is the assignment operator, assigning the value on the right-han d side to the identifier or other valid expression on the left-hand side.

syntax:

<restricted\_expression> := <expression>

<restricted\_expression> is ordinarily a single identifier, though simple expressions may be used (see Comments below). <expression> is any valid REDUCE expression. If <expression> is a matrix identifier, then <restricted\_expression> can be a matrix identifier (redimensioned if necessary) which has each element set to the corresponding elements of the identifier on the right-hand side.

examples:


a := x**2 + 1; 

        2
  A := X   + 1 


a; 

   2
  X  + 1 


first := second := third; 

  FIRST := SECOND := THIRD 


first; 

  THIRD 


second; 

  THIRD 


b := for i := 1:5 product i; 

  B := 120 


b; 

  120 


w + (c := x + 3) + z; 

  W + X + Z + 3 


c; 

  X + 3 


y + b := c; 

  Y + B := C 


y; 

  - (B - C)

The assignment operator is right associative, as shown in the seco nd and third examples. A string of such assignments has all but the last item set to the value of the last item. Embedding an assignment statement in another expression has the side effect of making the assignment, as well as causing the given replacement in the expression.

Assignments of values to expressions rather than simple identifiers (such as in the last example above) can also be done, subject to the following remarks:

_ _ _ (i) If the left-hand side is an identifier, an operator, or a power, the substitution rule is added to the rule table.

_ _ _ (ii) If the operators - + / appear on the left-hand side, all but the first term of the expression is moved to the right-hand side.

_ _ _ (iii) If the operator * appears on the left-hand side, any constant terms are moved to the right-hand side, but the symbolic factors remain.

Assignment is valid for array elements, but not for entire arrays. The assignment operator can also be used to attach functionality to operators.

A recursive construction such as a := a + b is allowed, but when a is referenced again, the process of resubstitution continues until the expression stack overflows (you get an error message). Recursive assignments can be done safely inside controlled loop expressions, such as for... or repeat...until.