Re: pure functions/methods

2012-04-20 Thread bearophile
Namespace: So only GDC optimized "pure" functions at all? I've seen DMD performs some optimizations with "strongly pure" functions that return integral values. If you have code like: int sqr(in int x) pure nothrow { return x * x; } int y = ... auto r = sqr(y) + sqr(y); I think DMD replac

Re: pure functions/methods

2012-04-20 Thread Namespace
On Friday, 20 April 2012 at 09:55:28 UTC, Timon Gehr wrote: On 04/20/2012 10:06 AM, Namespace wrote: The sense of pure functions isn't clear to me. What is the advantage of pure functions / methods? 1. It enables stateless reasoning about program parts. 2. It enables certain com

Re: pure functions/methods

2012-04-20 Thread Timon Gehr
On 04/20/2012 10:06 AM, Namespace wrote: The sense of pure functions isn't clear to me. What is the advantage of pure functions / methods? 1. It enables stateless reasoning about program parts. 2. It enables certain compiler optimizations. I inform the compiler with "const" t

Re: pure functions/methods

2012-04-20 Thread Sean Cavanaugh
On 4/20/2012 3:06 AM, Namespace wrote: The sense of pure functions isn't clear to me. What is the advantage of pure functions / methods? I inform the compiler with "const" that this method does not change the current object, and therefore he can optimize (at least in C++) this

Re: pure functions/methods

2012-04-20 Thread Ary Manzana
On 4/20/12 4:06 PM, Namespace wrote: The sense of pure functions isn't clear to me. What is the advantage of pure functions / methods? I inform the compiler with "const" that this method does not change the current object, and therefore he can optimize (at least in C++) this metho

pure functions/methods

2012-04-20 Thread Namespace
The sense of pure functions isn't clear to me. What is the advantage of pure functions / methods? I inform the compiler with "const" that this method does not change the current object, and therefore he can optimize (at least in C++) this method. How and what optimized the comp