Why is it that
x=5
x=x+1
nicely evaluates to 6, but the following
Remove[a,f,x]
a=5;
f[x_] := x = x+1
f[a]
evaluates to 5=6?
To my understanding, the only way I can get the result I'm getting would if when I call f[a], instead of first evaluating the LHS of from the "bottom to top", namely <x> -> <5+1> -> <x=6> -> f[5] = 6 (while setting x=6), but it seems this is not what is happening. Is it because function substitution preceded over delayed assignment, namely it is substituting the value of a before evaluating x=x+1?

SetAttributes[f, HoldFirst]. Also try inspecting functions that modify variables, for exampleAttributes[Increment]. – Sjoerd Smit Dec 21 '20 at 20:19Set::setraw: Cannot assign to raw object 5.) followed byTrue. To see the evaluation sequence with your version, add// Traceto the last line – Bob Hanlon Dec 21 '20 at 20:22