3 ms·
Checking for function purity is easier in some languages than others. It's mostly a transitive closure thing. Pure functions can call only pure functions. It's
by Animats 7y ago
Checking for function purity is easier in some languages than others. It's mostly a transitive closure thing. Pure functions can call only pure functions.
It's tough in Javascript, because function declaration is dynamic and you can rebind. It's not that tough in a more static language, where you can tell who calls whom at compile time.
Way too many years ago, I did that.[1], starting at line 204.
Knowing that a function is pure has many uses. You can optimize, using that x=y => f(x)=f(y). Pure functions can safely be used in assertions and conditional debug code.
[1] https://github.com/John-Nagle/pasv/blob/master/src/CPC2/p2trutil.i https://github.com/John-Nagle/pasv/blob/master/src/CPC2/p2tr...