
<A NAME=assign>

<TITLE>assign</TITLE></A>
<b><a href=r37_idx.html>INDEX</a></b><p><p>



<B>:=</B> _ _ _ <B>ASSIGN</B> _ _ _  _ _ _  _ _ _  _ _ _ <B>operator</B><P>
<P>
 
 <P>
<P>
The <em>:=</em> 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. 
<P>
<P>
 <P> <H3> 
syntax: </H3>
&lt;restricted\_expression&gt; <em>:=</em> &lt;expression&gt; 
<P>
<P>
<P>
&lt;restricted\_expression&gt; is ordinarily a single identifier, though simple 

expressions may be used (see Comments below). &lt;expression&gt; is any 
valid REDUCE expression. If &lt;expression&gt; is a 
<A HREF=r37_0345.html>matrix</A> 
identifier, then 
&lt;restricted\_expression&gt; 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. 
<P>
<P>
 <P> <H3> 
examples: </H3>
<P><PRE><TT>
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)

</TT></PRE><P>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. 
<P>
<P>
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: 
<P>
<P>
 _ _ _ (i) 
If the left-hand side is an identifier, an operator, or a power, the 
substitution rule is added to the rule table. 
<P>
<P>
 _ _ _ (ii) 
If the operators <em>- + /</em> appear on the left-hand side, all but the first 

term of the expression is moved to the right-hand side. 
<P>
<P>
 _ _ _ (iii) 
If the operator <em>*</em> appears on the left-hand side, any constant terms are
 
moved to the right-hand side, but the symbolic factors remain. 
<P>
<P>
Assignment is valid for 
<A HREF=r37_0188.html>array</A> elements, but not for entire arrays. 
The assignment operator can also be used to attach functionality to operators. 
<P>
<P>
A recursive construction such as <em>a := a + b</em> is allowed, but when 
<em>a</em> 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 
<A HREF=r37_0047.html>for</A>... or 
<A HREF=r37_0056.html>repeat</A>...<em>until</em>. 
<P>
<P>
<P>
<P>
