A little while ago I wondered why
f[x_] = f[x]
gives an infinite iteration. I ended up discovering the following difference in evaluation between Set and SetDelayed with Evaluate.
count = 0;
ClearAll @ a
a /; (count++ < 20) = {a}
a // OwnValues
count = 0;
a
Output
{{{{{{{{{{{{{{{{{{{{{a}}}}}}}}}}}}}}}}}}}}}
{HoldPattern[a /; count++ < 20] :> {a}}
{a}
and
count = 0;
ClearAll@b
b /; (count++ < 20) := Evaluate@{b}
b // OwnValues
count = 0;
b
Output
{HoldPattern[b /; count++ < 20] :> {b}}
{{{{{{{{{{{{{{{{{{{{b}}}}}}}}}}}}}}}}}}}}
Can somebody explain the difference? Can we say that there is an evaluation shortcut at work here?
Related
This is a follow up question: Strange results of definitions using OwnValues
Why x = x doesn't cause an infinite loop, but f[x_] := f[x] does?
Does Set vs. SetDelayed have any effect after the definition was done?
Update[]related mystery – Rojo Jan 10 '14 at 17:17UpValues(or perhaps you like upcode better :P). Clearly the XValues are some of those. Perhaps, when they overloaded theSetDelayedversions, they forgot to returnNull? – Rojo Jan 10 '14 at 17:22OwnValuesinvolved up code forOwnValues. I am writing a new question about this right now. – Jacob Akkerboom Jan 10 '14 at 17:27