3 ms·
> In C, this is easy! It can be done quickly and cleanly by adding some global variables. In purely functional code, this is somewhere between a major rearchite
by mercurial 11y ago
> In C, this is easy! It can be done quickly and cleanly by adding some global variables. In purely functional code, this is somewhere between a major rearchitecting of the data flow and hopeless.
"Cleanly" and "global variables" never mesh.
> Here's a simple statement:
if (a > 0) {
a++;
}
> In single-assignment form a new variable is introduced to avoid modifying an existing variable, and the result is rather Erlangy:
if (a > 0) {
a1 = a + 1;
} else {
a1 = a;
}
Er. Plenty of functional languages will let you shadow existing bindings:
let a = if a > 0 then a+1 else a
However, if you held a reference to 'a' before the shadowing, its value will not change.