Improvement in pure functions specification

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Tue Dec 20 17:02:11 PST 2016


On Tue, Dec 20, 2016 at 07:58:38PM -0500, Andrei Alexandrescu via Digitalmars-d wrote:
> On 12/20/16 7:40 PM, Timon Gehr wrote:
> > On 20.12.2016 23:49, Andrei Alexandrescu wrote:
> > > https://github.com/dlang/dlang.org/pull/1528 -- Andrei
> > 
> > Good, except:
> > 
> > "$(P `pure` functions returning `void` will be always called even if
> > it is strongly `pure`. The implementation must assume the function
> > does something outside the confines of the type system and is
> > therefore not allowed to elide the call, even if it appears to have
> > no possible effect.)"
> > 
> > I think this makes no sense. What is the idea behind this paragraph?
> 
> A function that traces execution via a debug statement, for example.
> -- Andrei

Isn't that impure by definition?!  How can tracing execution even be
remotely considered pure?

I understand that debug statements are a kind of backdoor to facilitate
debugging... but still. I'd expect we wouldn't bend the definition of
pure just for the sake of debugging -- that just sounds backwards. If a
function has side-effects outside of what's passed as arguments, I can't
see any way of justifying it being marked as pure.


T

-- 
They pretend to pay us, and we pretend to work. -- Russian saying


More information about the Digitalmars-d mailing list