Re: pure functions

2016-09-13 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, September 13, 2016 20:08:22 Patrick Schluter via Digitalmars-d- learn wrote: > On Tuesday, 13 September 2016 at 06:59:10 UTC, Jonathan M Davis > > wrote: > > On Tuesday, September 13, 2016 03:33:04 Ivy Encarnacion via > > > > Digitalmars-d- learn wrote: > > A pure function cannot call

Re: pure functions

2016-09-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/13/16 4:08 PM, Patrick Schluter wrote: On Tuesday, 13 September 2016 at 06:59:10 UTC, Jonathan M Davis wrote: On Tuesday, September 13, 2016 03:33:04 Ivy Encarnacion via Digitalmars-d- learn wrote: A pure function cannot call any function that is not pure [...] I've read that a lot but

Re: pure functions

2016-09-13 Thread Patrick Schluter via Digitalmars-d-learn
On Tuesday, 13 September 2016 at 06:59:10 UTC, Jonathan M Davis wrote: On Tuesday, September 13, 2016 03:33:04 Ivy Encarnacion via Digitalmars-d- learn wrote: A pure function cannot call any function that is not pure [...] I've read that a lot but it's not true. A pure function can call imp

Re: pure functions

2016-09-13 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, September 13, 2016 03:33:04 Ivy Encarnacion via Digitalmars-d- learn wrote: > Can pure functions throw exceptions on its arguments? Also, how > can it perform impure operations? Yes, as long as the exception's constructor is pure, a pure function can throw an exception. However, whethe

Re: pure functions

2016-09-12 Thread sarn via Digitalmars-d-learn
On Tuesday, 13 September 2016 at 03:33:04 UTC, Ivy Encarnacion wrote: Can pure functions throw exceptions on its arguments? You can throw exceptions for whatever reasons from a function marked pure: void foo() pure { throw new Exception("nope"); } void main() { foo(); } Al

Re: pure functions calling impure functions at compile-time

2012-05-24 Thread Don Clugston
On 23/05/12 11:41, bearophile wrote: Simen Kjaeraas: Should this be filed as a bug, or is the plan that only pure functions be ctfe-able? (or has someone already filed it, perhaps) It's already in Bugzilla, see issue 7994 and 6169. It's just happening because the purity checking is currentl

Re: pure functions calling impure functions at compile-time

2012-05-23 Thread bearophile
Simen Kjaeraas: Should this be filed as a bug, or is the plan that only pure functions be ctfe-able? (or has someone already filed it, perhaps) It's already in Bugzilla, see issue 7994 and 6169. But I think there is a semantic hole in some of the discussions about this problem. Is a future

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 compiler optimizat

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" that this method d

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 method. How and wha

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 method. How and what

Re: Pure functions and delegates

2012-01-18 Thread Timon Gehr
On 01/18/2012 04:40 AM, H. S. Teoh wrote: So, I was quite impressed with D's pureness system, and was experimenting a bit with it. Then I discovered that delegates are impure, which seems reasonable since there's no way to know what a delegate might do. But *if* the compiler verifies that a parti