Error: recursive assignment

This occurs when you attempt to assign a variable a value which contains the name of that variable.

> x:= 'x':
x:= x + 1;

Error, recursive assignment

If Maple were to accept this assignment (as it did in previous releases), trouble would occur if you attempted to evaluate x . Maple would first replace x by its value x+1 . But then x+1 must be evaluated, obtaining x+2 . The process would continue in what would be an infinite loop, except that Maple would run out of stack space and produces an error message.

The construction x:= x+1 would have been legitimate if x had originally been assigned a value (not depending on x itself). Then the x on the right side would have been evaluated first, and the result would be simply to increase the value of x by 1.

> x:= 3:
x:= x+1;

x := 4

Thus a common case where this error arises is when you attempt to change the value of a loop variable, but forget to give this variable an initial value.

The error also does not arise in defining a function. Recursive definitions of functions can be quite legitimate. Of course you should provide some way of avoiding an infinite loop in evaluating the function.

> fact:= t -> t*fact(t-1);

fact := proc (t) options operator, arrow; t*fact(t-...

> fact(0):= 1:

> fact(10);

3628800

See also: assignment , Assignments do not commute , Error: too many levels of recursion

Maple Advisor Database R. Israel, 2000