Purity

Bruno Medeiros brunodomedeiros+spam at com.gmail
Thu Jan 27 11:11:30 PST 2011


On 18/12/2010 08:52, spir wrote:
> On Fri, 17 Dec 2010 02:42:14 -0500
> bearophile<bearophileHUGS at lycos.com>  wrote:
>
>> http://www.reddit.com/r/programming/comments/enajl/purity_in_d_language/
>>
>> Bye,
>> bearophile
>
> I take the opportunity to question the def of weakly pure.
>
> -1- How can this even compile?
> 	pure append (ref int[] a, int i) {a ~= i;}
> The _only_ task of this func is to change state.
>

It is best not to think of D's pure as saying the function is pure in 
the traditional sense (side-effect free), but rather to say the 
side-effects are confined to the function's parameters only (and the 
state/data that is transitively reachable from them).

The key benefit of this is that it allows the *caller* of such pure 
function to determine which subset of state/data *may* change by a call 
to such function.



-- 
Bruno Medeiros - Software Engineer


More information about the Digitalmars-d mailing list