Improvement in pure functions specification

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Tue Dec 20 17:05:50 PST 2016


On Tuesday, December 20, 2016 19:58:38 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

Well, ultimately, strongly pure functions that return void are either doing
something that works around the type system (e.g. using debug statements to
do operations which aren't pure), or they arguably shouldn't even compile,
because they can't possibly do anything that has any effect on the program
beyond eating up CPU time. So, as far as I can tell, we should either make
an exception for them (as the PR currently does) or make them illegal.

- Jonathan M Davis



More information about the Digitalmars-d mailing list