Proposal: Relax rules for 'pure'

Jason House jason.james.house at gmail.com
Wed Sep 22 06:16:37 PDT 2010


I think you need to forbid access to shared state as well. It's possible to allow it if a strongly pure function calls a weakly pure function in an object that it created, but that seems unnecessarily complex. Actually, that makes me wonder: can constructors be marked pure?

Don Wrote:

> Don wrote:
> > The docs currently state that:
> 
> > PROPOSAL:
> > Drop the first requirement. Only one requirement is necessary:
> > 
> > A pure function does not read or write any global mutable state.
> > 
> 
> Wow. It seems that not one person who has responded so far has 
> understood this proposal! I'll try again. Under this proposal:
> 
> If you see a function which has mutable parameters, but is marked as 
> 'pure', you can only conclude that it doesn't use global variables. 
> That's not much use on it's own. Let's call this a 'weakly-pure' function.
> 
> However, if you see a function maked as 'pure', which also has only 
> immutable parameters, you have the same guarantee which 'pure' gives us 
> as the moment. Let's call this a 'strongly-pure' function.
> 
> The benefit of the relaxed rule is that a strongly-pure function can 
> call a weakly-pure functions, while remaining strongly-pure.
> This allows very many more functions to become strongly pure.
> 
> The point of the proposal is *not* to provide the weak guarantee. It is 
> to provide the strong guarantee in more situations.



More information about the Digitalmars-d mailing list