Consider the following program in "mutable style":
x=1 x=f(x); x=f(x);
We can rewrite this in "immutable style" without changing the higher-level structure of the program:
x1=1 x2=f(x1); x3=f(x2);
We turned it into an immutable style program by only making "local changes": We simply took the mutable variable $x$ and changed the program wherever $x$ appeared to make it immutable.
Question: Can we in general turn an arbitrary mutable program into an immutable program by only making local changes, so that the higher level structure of the program stays the same?
- Obviously this will depend on the language. You may assume any language features you want. e.g. this answer talks about monads (though it's not clear to me whether they can always be used to translate programs using only local changes).