If I execute:
In[1] := x = x
Out[1] = x
and then I evaluate the symbol x
:
In[2] := x
Out[2] = x
it simply returns x
itself. I don't understand why this doesn't result in an infinite loop. Given that x
references itself after the assignment x = x
, I think that evaluating x
should result in an infinite loop (x
is replaced by x
, which is replaced x
, and so on). What am I missing?
Contrast this with what happens with the assignment:
f[x_] := f[x]
Evaluating f[x]
after this assignment results in an infinite loop:
In[5]:= f[x]
During evaluation of In[5]:= $IterationLimit::itlim: Iteration limit of 4096 exceeded.
Out[5]= Hold[f[x]]
Edit: Using x := x
instead of x = x
does not cause an infinite loop. Using x = Identity[x]
does not cause an infinite loop either. But using x := Identity[x]
as suggested by Jacob Akkerboom in the comments results in an infinite loop. Why?
Comments
Post a Comment