07.11.2013 21:41, H. S. Teoh пишет:
On Thu, Nov 07, 2013 at 09:22:47PM +0400, Denis Shelomovskij wrote:
01.11.2013 0:05, H. S. Teoh пишет:
I'd like to propose extending the scope of weak purity one step
further: allow weakly-pure functions to call (not necessarily pure)
delegates passed as a parameter.

Unacceptable. It will break strongly purity. Your mistake is
strongly pure function can easily get an impure delegate:
[...]

It will not. My proposal only applies to weakly pure functions. Strongly
pure functions cannot call impure delegates because you cannot guarantee
anything about what the delegate will do.

So basically, once a pure function takes a non-pure delegate parameter,
it is no longer strongly pure, only weakly pure. (I stated this at the
end of my post where strongly pure functions are not allowed to call
impure delegates.)


T


Let me repeat my code again:
---
int i;

struct S
{ void g() { ++i; } }

void impureCaller(scope void delegate() del) pure
{ del(); }

void f() pure // strongly pure, will modify `i`
{
    S s;
    impureCaller(&s.g);
}
---

Currently the only error is in `impureCaller` body. You propose to make `impureCaller`'s body valid thus making the code compilable. Do you also propose some breaking changes to make `f` body invalid? I see no "breaking changes" notes in you "nutshell" at the end. Looks like you either didn't think enough about such cases or you propose to make it impossible to detect whether the function is strongly pure by it's signature.

--
Денис В. Шеломовский
Denis V. Shelomovskij

Reply via email to