On Tue, Nov 12, 2013 at 12:06:25AM +0400, Denis Shelomovskij wrote: > 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? [...]
It should be illegal to take the address of S.g in f() if f is pure. T -- You have to expect the unexpected. -- RL