3 ms·
The reason for "weakly pure" was first discovered by Don Clugston (as far as I can tell). Suppose I have a struct with a member function: struct S { int s;
by WalterBright 12y ago
The reason for "weakly pure" was first discovered by Don Clugston (as far as I can tell). Suppose I have a struct with a member function:
struct S { int s; pure void set(int i) { s = i; }
Now, even in a strongly pure function, I can use the weakly pure function even though it is mutating state through its arguments:
pure int foo(int i) {
S s;
s.set(i);
...
return whatever;
}
I.e. when the effects of a weakly pure function are localized like in the example, they can be called from a strongly pure function and the strongly pure one will remain strongly pure.
It's a really cool idea and it took me a bit to get it, but Don was persistent in explaining it to me :-)