Given pure + @safe + immutable arguments, how is it not referentially transparent? (we ignore the practical concessions: debug statements, memory management, termination, floating point hardware state)
Edit: To be clear, I don't really feel too strongly about it. It's still leagues ahead of many other languages - I just think that particular choice of keyword is likely to confuse things a bit.
That is to say (in not necessarily real D, just close enough) given:
int global_var
void modify_global(int z) {
global_var += z;
return global_var;
}
pure int foo(int x) {
return x + modify_global(2);
}
What happens? Does the compiler barf because it causes modification to something not passed? If so, assuming that you can only modify the object passed (via methods of it, and presumably, the things that object points to in its members),then it maintains something much closer to referential transparency than you are implying.
/d111/f857.d(9): Error: pure function 'f857.foo' cannot call impure function 'f857.modify_global'Nope (it would be a useless feature if it could).