Re: pure functions cannot be removed, actually: pure vs. total

2018-06-11 Thread Steven Schveighoffer via Digitalmars-d
On 6/11/18 2:23 PM, Timon Gehr wrote: On 11.06.2018 20:15, Steven Schveighoffer wrote: On 6/11/18 10:43 AM, Timon Gehr wrote: On 11.06.2018 16:39, Timon Gehr wrote: FeepingCreature's example does not really qualify as a do-nothing loop, because the loop produces a value that you

Re: pure functions cannot be removed, actually: pure vs. total

2018-06-11 Thread Timon Gehr via Digitalmars-d
On 11.06.2018 20:15, Steven Schveighoffer wrote: On 6/11/18 10:43 AM, Timon Gehr wrote: On 11.06.2018 16:39, Timon Gehr wrote: FeepingCreature's example does not really qualify as a do-nothing loop, because the loop produces a value that you (presumably) later access. Hm, ok. The problem

Re: pure functions cannot be removed, actually: pure vs. total

2018-06-11 Thread Steven Schveighoffer via Digitalmars-d
On 6/11/18 10:43 AM, Timon Gehr wrote: On 11.06.2018 16:39, Timon Gehr wrote: FeepingCreature's example does not really qualify as a do-nothing loop, because the loop produces a value that you (presumably) later access. Hm, ok. The problem is actually there, but it is not that the 'find'

Re: pure functions cannot be removed, actually: pure vs. total

2018-06-11 Thread Timon Gehr via Digitalmars-d
On 11.06.2018 16:39, Timon Gehr wrote: FeepingCreature's example does not really qualify as a do-nothing loop, because the loop produces a value that you (presumably) later access. Hm, ok. The problem is actually there, but it is not that the 'find' call will get removed, it is that the

Re: pure functions cannot be removed, actually: pure vs. total

2018-06-11 Thread Timon Gehr via Digitalmars-d
On 08.06.2018 01:14, Steven Schveighoffer wrote: No matter what is inside fn, it will return S.init, if it returns. The question to answer is, can we assume all functions don't enter infinite loops, and if we can assume this, then why couldn't the compiler simply replace a call to fn with

Re: pure functions cannot be removed, actually: pure vs. total

2018-06-07 Thread Steven Schveighoffer via Digitalmars-d
On 6/7/18 6:57 PM, Stefan Koch wrote: On Thursday, 7 June 2018 at 22:23:09 UTC, Steven Schveighoffer wrote: {...} That a function could return does not mean it will. int fn (int arg) /*strongly*/ pure {   if (arg == 42)     return 42;   else (arg < 43)     return fn(--arg);   else    

Re: pure functions cannot be removed, actually: pure vs. total

2018-06-07 Thread Stefan Koch via Digitalmars-d
On Thursday, 7 June 2018 at 22:23:09 UTC, Steven Schveighoffer wrote: {...} That a function could return does not mean it will. int fn (int arg) /*strongly*/ pure { if (arg == 42) return 42; else (arg < 43) return fn(--arg); else return fn(++arg); } do you see the problem?

Re: pure functions cannot be removed, actually: pure vs. total

2018-06-07 Thread Steven Schveighoffer via Digitalmars-d
On 6/7/18 5:04 PM, Jonathan M Davis wrote: On Thursday, June 07, 2018 20:14:19 Johan Engelen via Digitalmars-d wrote: On Tuesday, 5 June 2018 at 14:48:23 UTC, FeepingCreature wrote: I'm just posting to clear up the misunderstanding that a call to a pure function can be removed. Actually, even

Re: pure functions cannot be removed, actually: pure vs. total

2018-06-07 Thread Jonathan M Davis via Digitalmars-d
On Thursday, June 07, 2018 20:14:19 Johan Engelen via Digitalmars-d wrote: > On Tuesday, 5 June 2018 at 14:48:23 UTC, FeepingCreature wrote: > > I'm just posting to clear up the misunderstanding that a call > > to a pure function can be removed. Actually, even calls to > > strongly pure functions

Re: pure functions cannot be removed, actually: pure vs. total

2018-06-07 Thread Johan Engelen via Digitalmars-d
On Tuesday, 5 June 2018 at 14:48:23 UTC, FeepingCreature wrote: I'm just posting to clear up the misunderstanding that a call to a pure function can be removed. Actually, even calls to strongly pure functions cannot always be removed. This is because there is one thing that a pure function can

Re: pure functions cannot be removed, actually: pure vs. total

2018-06-05 Thread Steven Schveighoffer via Digitalmars-d
On 6/5/18 5:03 PM, FeepingCreature wrote: On Tuesday, 5 June 2018 at 17:47:15 UTC, Steven Schveighoffer wrote: Another observation: under the "infinite loops are important observable behavior" world-view, pure functions cannot be lazily evaluated either: pure int foo() { /*infinite loop */}

Re: pure functions cannot be removed, actually: pure vs. total

2018-06-05 Thread FeepingCreature via Digitalmars-d
On Tuesday, 5 June 2018 at 17:47:15 UTC, Steven Schveighoffer wrote: Another observation: under the "infinite loops are important observable behavior" world-view, pure functions cannot be lazily evaluated either: pure int foo() { /*infinite loop */} void main(string[] args) { auto a =

Re: pure functions cannot be removed, actually: pure vs. total

2018-06-05 Thread Steven Schveighoffer via Digitalmars-d
On 6/5/18 10:48 AM, FeepingCreature wrote: I'm just posting to clear up the misunderstanding that a call to a pure function can be removed. Actually, even calls to strongly pure functions cannot always be removed. This is because there is one thing that a pure function can do that will change

Re: pure functions cannot be removed, actually: pure vs. total

2018-06-05 Thread Stefan Koch via Digitalmars-d
On Tuesday, 5 June 2018 at 14:48:23 UTC, FeepingCreature wrote: I'm just posting to clear up the misunderstanding that a call to a pure function can be removed. Actually, even calls to strongly pure functions cannot always be removed. This is because there is one thing that a pure function can

pure functions cannot be removed, actually: pure vs. total

2018-06-05 Thread FeepingCreature via Digitalmars-d
I'm just posting to clear up the misunderstanding that a call to a pure function can be removed. Actually, even calls to strongly pure functions cannot always be removed. This is because there is one thing that a pure function can do that will change program behavior if it is removed, even if