Implicit conversions through purity

Steve Teale steve.teale at britseyeview.com
Tue Apr 15 09:50:06 PDT 2014


On Tuesday, 15 April 2014 at 09:41:57 UTC, bearophile wrote:
> Yes, foo2 is weakly pure, but main is not tagged as pure, so 
> main is free to use a global reference. If you mark main pure, 
> your code will not compile even if you comment out the writeln. 
> D is working as designed here.
>
>
>> 3) Using a ref parameter for a pure function seems to me to be 
>> a clear indication of intended side effect.
>
> In D you can also have "const ref". A mutable ref makes the 
> function "weakly pure" at best.
>
>
>> Wikipedia on pure functions says it's not allowed.
>
> D has both strongly pure and weakly pure functions (and later 
> the compiler has added "const-ly pure" and another category, 
> all invisible.
>
>
>> Out does seem somehow different to me, since it's initial
>> value is by definition throw-away.
>
> Yes, this is true in theory. I don't know if this is also true 
> in D in practice, because D out has some problems.
>
> Bye,
> bearophile

Since this is D-Learn, I can be indignant, and say that D needs 
to get its act together, and have a clean definition of 'pure'. 
What you describe is not only undocumented, but also far too 
complicated - pure weak nothrow dontpiss kissmyass @never, and so 
on if the direction continues.

Nontheless, thank you for your assiduous efforets to make D 
internally consistent.

Steve



More information about the Digitalmars-d-learn mailing list