Re: To help LDC/GDC

2013-05-02 Thread bearophile
To: NG D Subject: Re: To help LDC/GDC This D code comes from a Haskell solution by tanakh of the Lawnmower problem of the Google Code Jam 2013 Qualification Round: import std.stdio, std.string, std.conv, std.range, std.algorithm; void main() { immutable n = stdin.readln.strip.to!int

Re: To help LDC/GDC

2013-04-11 Thread Joseph Rushton Wakeling
On 04/10/2013 08:39 PM, Walter Bright wrote: Sure there is. Declare the function as pure, and the function's parameters as const or immutable. Sure, I accept that. What I was meaning, though, was an up-front declaration which would make the compiler shout if those necessary conditions were not

Re: To help LDC/GDC

2013-04-11 Thread deadalnix
On Thursday, 11 April 2013 at 00:41:01 UTC, Walter Bright wrote: On 4/10/2013 5:33 PM, deadalnix wrote: call with const parameter can be considered strongly pure if the argument is immutable The argument doesn't need to be immutable because nobody can change it while the function is

Re: To help LDC/GDC

2013-04-11 Thread deadalnix
On Thursday, 11 April 2013 at 08:36:13 UTC, Joseph Rushton Wakeling wrote: On 04/10/2013 08:39 PM, Walter Bright wrote: Sure there is. Declare the function as pure, and the function's parameters as const or immutable. Sure, I accept that. What I was meaning, though, was an up-front

Re: To help LDC/GDC

2013-04-11 Thread Simen Kjærås
On Thu, 11 Apr 2013 12:03:38 +0200, deadalnix deadal...@gmail.com wrote: On Thursday, 11 April 2013 at 08:36:13 UTC, Joseph Rushton Wakeling wrote: On 04/10/2013 08:39 PM, Walter Bright wrote: Sure there is. Declare the function as pure, and the function's parameters as const or immutable.

Re: To help LDC/GDC

2013-04-11 Thread John Colvin
On Thursday, 11 April 2013 at 10:03:39 UTC, deadalnix wrote: On Thursday, 11 April 2013 at 08:36:13 UTC, Joseph Rushton Wakeling wrote: On 04/10/2013 08:39 PM, Walter Bright wrote: Sure there is. Declare the function as pure, and the function's parameters as const or immutable. Sure, I

Re: To help LDC/GDC

2013-04-11 Thread kenji hara
2013/4/11 John Colvin john.loughran.col...@gmail.com On Thursday, 11 April 2013 at 10:03:39 UTC, deadalnix wrote: On Thursday, 11 April 2013 at 08:36:13 UTC, Joseph Rushton Wakeling wrote: On 04/10/2013 08:39 PM, Walter Bright wrote: Sure there is. Declare the function as pure, and the

Re: To help LDC/GDC

2013-04-11 Thread John Colvin
On Thursday, 11 April 2013 at 10:27:55 UTC, kenji hara wrote: 2013/4/11 John Colvin john.loughran.col...@gmail.com On Thursday, 11 April 2013 at 10:03:39 UTC, deadalnix wrote: On Thursday, 11 April 2013 at 08:36:13 UTC, Joseph Rushton Wakeling wrote: On 04/10/2013 08:39 PM, Walter Bright

Re: To help LDC/GDC

2013-04-11 Thread Joseph Rushton Wakeling
On 04/11/2013 12:03 PM, deadalnix wrote: Both are strongly pure. Perhaps the fact that I can have this misunderstanding is itself an argument for an explicit strong pure keyword, so that a daft bugger like me can really be sure he's getting what he thinks he's getting? :-) Apart from that, I

Re: To help LDC/GDC

2013-04-11 Thread deadalnix
On Thursday, 11 April 2013 at 10:16:39 UTC, John Colvin wrote: On Thursday, 11 April 2013 at 10:03:39 UTC, deadalnix wrote: On Thursday, 11 April 2013 at 08:36:13 UTC, Joseph Rushton Wakeling wrote: On 04/10/2013 08:39 PM, Walter Bright wrote: Sure there is. Declare the function as pure, and

Re: To help LDC/GDC

2013-04-11 Thread Jacob Carlborg
On 2013-04-11 12:09, Simen Kjærås wrote: That's not the point. The point is, if he'd written this: strong pure bar(int* n) { ... } The compiler would have said 'Bad programmer! int* is not implicitly castable to immutable!' What's the point of that. Just have strong mean const/immutable

Re: To help LDC/GDC

2013-04-11 Thread Joseph Rushton Wakeling
On 04/11/2013 03:29 PM, Jacob Carlborg wrote: What's the point of that. Just have strong mean const/immutable parameters. The point is to have a way for me, the programmer, to say to the compiler: I mean for this function to be strongly pure, can you confirm whether my choice of function inputs

Re: To help LDC/GDC

2013-04-11 Thread Iain Buclaw
On 11 April 2013 11:09, Simen Kjærås simen.kja...@gmail.com wrote: On Thu, 11 Apr 2013 12:03:38 +0200, deadalnix deadal...@gmail.com wrote: On Thursday, 11 April 2013 at 08:36:13 UTC, Joseph Rushton Wakeling wrote: On 04/10/2013 08:39 PM, Walter Bright wrote: Sure there is. Declare the

Re: To help LDC/GDC

2013-04-11 Thread Iain Buclaw
On 11 April 2013 14:38, Joseph Rushton Wakeling joseph.wakel...@webdrake.net wrote: On 04/11/2013 03:29 PM, Jacob Carlborg wrote: What's the point of that. Just have strong mean const/immutable parameters. The point is to have a way for me, the programmer, to say to the compiler: I mean

Re: To help LDC/GDC

2013-04-11 Thread Joseph Rushton Wakeling
On 04/11/2013 03:49 PM, Iain Buclaw wrote: Great, just what we need. A compiler that barrages the user about how bad his code is, then dies... Compiler says no ...

Re: To help LDC/GDC

2013-04-11 Thread Joseph Rushton Wakeling
On 04/11/2013 03:53 PM, Iain Buclaw wrote: I think that giving the user choice of purity is about as useful as given user choice over what functions should be inlined, or what vars should go in registers. Well, I don't mean the compiler should guarantee that my code will be optimized in a

Re: To help LDC/GDC

2013-04-11 Thread Walter Bright
On 4/11/2013 3:02 AM, deadalnix wrote: On Thursday, 11 April 2013 at 00:41:01 UTC, Walter Bright wrote: On 4/10/2013 5:33 PM, deadalnix wrote: call with const parameter can be considered strongly pure if the argument is immutable The argument doesn't need to be immutable because nobody can

Re: To help LDC/GDC

2013-04-11 Thread Jacob Carlborg
On 2013-04-11 15:53, Iain Buclaw wrote: I think that giving the user choice of purity is about as useful as given user choice over what functions should be inlined, or what vars should go in registers. Such decisions are best left to the compiler devs judgement on doing the right thing for

Re: To help LDC/GDC

2013-04-11 Thread Jacob Carlborg
On 2013-04-11 15:38, Joseph Rushton Wakeling wrote: The point is to have a way for me, the programmer, to say to the compiler: I mean for this function to be strongly pure, can you confirm whether my choice of function inputs supports this please? Why should I have to explicitly specify

Re: To help LDC/GDC

2013-04-11 Thread Timon Gehr
On 04/11/2013 07:48 AM, Walter Bright wrote: On 4/10/2013 10:44 PM, Timon Gehr wrote: On 04/10/2013 11:50 PM, Walter Bright wrote: ... My point was that competing designs are very probably not necessary. We just need to pull on the string on what must be. Yes, IMO it is quite obvious how

Re: To help LDC/GDC

2013-04-11 Thread Joseph Rushton Wakeling
On 04/11/2013 08:16 PM, Jacob Carlborg wrote: Why should I have to explicitly specify immutable when that could be default for strongly pure functions? Oh, sorry, I misunderstood your meaning. I thought you were saying that a strong pure keyword wasn't necessary because it was sufficient to

Re: To help LDC/GDC

2013-04-11 Thread deadalnix
On Thursday, 11 April 2013 at 17:52:43 UTC, Walter Bright wrote: On 4/11/2013 3:02 AM, deadalnix wrote: On Thursday, 11 April 2013 at 00:41:01 UTC, Walter Bright wrote: On 4/10/2013 5:33 PM, deadalnix wrote: call with const parameter can be considered strongly pure if the argument is

Re: To help LDC/GDC

2013-04-10 Thread Dicebot
On Wednesday, 10 April 2013 at 01:37:35 UTC, deadalnix wrote: Agree on it being great and innovative. But I fail to see usefulness with current design. Can you provide examples how current pure design allows for better code / optimizations? Strongly pure functions can call weakly pure

Re: To help LDC/GDC

2013-04-10 Thread deadalnix
On Wednesday, 10 April 2013 at 08:19:26 UTC, Dicebot wrote: On Wednesday, 10 April 2013 at 01:37:35 UTC, deadalnix wrote: Agree on it being great and innovative. But I fail to see usefulness with current design. Can you provide examples how current pure design allows for better code /

Re: To help LDC/GDC

2013-04-10 Thread Dicebot
On Wednesday, 10 April 2013 at 11:22:41 UTC, deadalnix wrote: On Wednesday, 10 April 2013 at 08:19:26 UTC, Dicebot wrote: On Wednesday, 10 April 2013 at 01:37:35 UTC, deadalnix wrote: Agree on it being great and innovative. But I fail to see usefulness with current design. Can you provide

Re: To help LDC/GDC

2013-04-10 Thread Andrei Alexandrescu
On 4/10/13 7:29 AM, Dicebot wrote: On Wednesday, 10 April 2013 at 11:22:41 UTC, deadalnix wrote: On Wednesday, 10 April 2013 at 08:19:26 UTC, Dicebot wrote: On Wednesday, 10 April 2013 at 01:37:35 UTC, deadalnix wrote: Agree on it being great and innovative. But I fail to see usefulness with

Re: To help LDC/GDC

2013-04-10 Thread deadalnix
On Wednesday, 10 April 2013 at 11:29:42 UTC, Dicebot wrote: Except you can't be sure that your function is strongly pure with current design. Add ref parameter into the mix by accident and it will silently change to weak pure which is useless by its own. pure + immutable and value parameters

Re: To help LDC/GDC

2013-04-10 Thread Timon Gehr
On 04/10/2013 05:43 PM, deadalnix wrote: On Wednesday, 10 April 2013 at 11:29:42 UTC, Dicebot wrote: Except you can't be sure that your function is strongly pure with current design. Add ref parameter into the mix by accident and it will silently change to weak pure which is useless by its own.

Re: To help LDC/GDC

2013-04-10 Thread deadalnix
On Wednesday, 10 April 2013 at 15:48:43 UTC, Timon Gehr wrote: On 04/10/2013 05:43 PM, deadalnix wrote: On Wednesday, 10 April 2013 at 11:29:42 UTC, Dicebot wrote: Except you can't be sure that your function is strongly pure with current design. Add ref parameter into the mix by accident and

Re: To help LDC/GDC

2013-04-10 Thread Dicebot
On Wednesday, 10 April 2013 at 15:52:23 UTC, deadalnix wrote: ... And that is exactly what makes it useless. I need one keyword to automatically verify for me that parameters fine, that context is fine, return value is fine etc. This is the basic crucial concept and everything else should

Re: To help LDC/GDC

2013-04-10 Thread Walter Bright
On 4/9/2013 1:33 AM, Manu wrote: How can 'weak pure' reasonably be called any kind of 'pure'? It's not pure at all. The function returns a completely different result when called twice. That's the definition of not-pure. I suggest that no D language newbie would ever reasonably expect that

Re: To help LDC/GDC

2013-04-10 Thread Walter Bright
On 4/9/2013 1:04 AM, Dicebot wrote: On Tuesday, 9 April 2013 at 07:57:37 UTC, Manu wrote: Are you saying the example above is not actually valid code? struct Foo { int a = 0; pure int bar( int n ) { // Weakly pure a += n; return a; } } That's not pure. Call it

Re: To help LDC/GDC

2013-04-10 Thread Walter Bright
On 4/9/2013 5:56 AM, Andrei Alexandrescu wrote: s/body/signature/ s/Crap/Awesome/ I agree that the notions of strong/weak purity are awesome, I believe they are a D innovation, and if I recall correctly this innovation is thanks to Don Clugston, one of our most awesome contributors.

Re: To help LDC/GDC

2013-04-10 Thread Walter Bright
On 4/9/2013 6:49 AM, Dicebot wrote: Not gonna argue latter but former is just wrong. struct Test { int a; pure int foo1() // strong pure { return 42; } pure int foo2() // weak pure { return a++; } } Signature is the same for both functions.

Re: To help LDC/GDC

2013-04-10 Thread Walter Bright
On 4/9/2013 7:12 AM, Simen Kjærås wrote: const is not sufficient, as someone else might have a mutable reference. immutable is needed. const is sufficient for strongly pure, because another reference is not available to the function body, and so the function cannot mutate it.

Re: To help LDC/GDC

2013-04-10 Thread Walter Bright
On 4/9/2013 7:50 AM, Simen Kjærås wrote: It's based purely on function signature Correct. (I should point out that there are cases where the compiler infers purity from the function body: 1. lambdas 2. template functions 3. auto functions )

Re: To help LDC/GDC

2013-04-10 Thread Walter Bright
On 4/9/2013 3:52 AM, Joseph Rushton Wakeling wrote: I do agree that it's a great pity there is not a way to declare strong purity for D functions. Sure there is. Declare the function as pure, and the function's parameters as const or immutable.

Re: To help LDC/GDC

2013-04-10 Thread Walter Bright
On 4/9/2013 12:52 AM, Manu wrote: But that's meaningless though, because there's always the possibility that something somewhere else may have a non-const reference to that thing. Can you suggest a case where const could EVER be used in any sort of optimisation? Sure: pure int bar(const

Re: To help LDC/GDC

2013-04-10 Thread Walter Bright
On 4/9/2013 1:00 AM, Manu wrote: Locals or allocated memory are not thread-local, can be passed wherever they want, including other threads. Not unless they are marked as shared.

Re: To help LDC/GDC

2013-04-10 Thread Walter Bright
On 4/9/2013 3:48 AM, deadalnix wrote: No, D have holes in its type system and so can't ensure anything. It has been show many many many times, especially by Timon and myself, and I'm kind of fed up to have to repeat that again and again, especiallt since fix proposal have recieved no attention

Re: To help LDC/GDC

2013-04-10 Thread Andrei Alexandrescu
On 4/10/13 2:54 PM, Walter Bright wrote: On 4/9/2013 3:48 AM, deadalnix wrote: No, D have holes in its type system and so can't ensure anything. It has been show many many many times, especially by Timon and myself, and I'm kind of fed up to have to repeat that again and again, especiallt since

Re: To help LDC/GDC

2013-04-10 Thread Timon Gehr
On 04/10/2013 08:54 PM, Walter Bright wrote: On 4/9/2013 3:48 AM, deadalnix wrote: No, D have holes in its type system and so can't ensure anything. It has been show many many many times, especially by Timon and myself, and I'm kind of fed up to have to repeat that again and again, especiallt

Re: To help LDC/GDC

2013-04-10 Thread Walter Bright
On 4/10/2013 12:43 PM, Timon Gehr wrote: Generally it does not, but is it actually not full of holes in this case? Can you give a short wrap-up of what the original language design is for type checking delegate context pointers? We can only guess, because it is not specified and much of what DMD

Re: To help LDC/GDC

2013-04-10 Thread Andrei Alexandrescu
On 4/10/13 5:25 PM, Walter Bright wrote: On 4/10/2013 12:43 PM, Timon Gehr wrote: Generally it does not, but is it actually not full of holes in this case? Can you give a short wrap-up of what the original language design is for type checking delegate context pointers? We can only guess,

Re: To help LDC/GDC

2013-04-10 Thread Walter Bright
On 4/10/2013 2:28 PM, Andrei Alexandrescu wrote: On 4/10/13 5:25 PM, Walter Bright wrote: On 4/10/2013 12:43 PM, Timon Gehr wrote: Generally it does not, but is it actually not full of holes in this case? Can you give a short wrap-up of what the original language design is for type checking

Re: To help LDC/GDC

2013-04-10 Thread deadalnix
On Wednesday, 10 April 2013 at 17:12:27 UTC, Dicebot wrote: On Wednesday, 10 April 2013 at 15:52:23 UTC, deadalnix wrote: ... And that is exactly what makes it useless. I need one keyword to automatically verify for me that parameters fine, that context is fine, return value is fine etc.

Re: To help LDC/GDC

2013-04-10 Thread deadalnix
On Wednesday, 10 April 2013 at 18:33:26 UTC, Walter Bright wrote: On 4/9/2013 7:12 AM, Simen Kjærås wrote: const is not sufficient, as someone else might have a mutable reference. immutable is needed. const is sufficient for strongly pure, because another reference is not available to the

Re: To help LDC/GDC

2013-04-10 Thread deadalnix
On Wednesday, 10 April 2013 at 18:54:15 UTC, Walter Bright wrote: On 4/9/2013 3:48 AM, deadalnix wrote: No, D have holes in its type system and so can't ensure anything. It has been show many many many times, especially by Timon and myself, and I'm kind of fed up to have to repeat that again

Re: To help LDC/GDC

2013-04-10 Thread Walter Bright
On 4/10/2013 5:33 PM, deadalnix wrote: call with const parameter can be considered strongly pure if the argument is immutable The argument doesn't need to be immutable because nobody can change it while the function is running.

Re: To help LDC/GDC

2013-04-10 Thread Zach the Mystic
On Wednesday, 10 April 2013 at 18:24:22 UTC, Walter Bright wrote: On 4/9/2013 1:33 AM, Manu wrote: How can 'weak pure' reasonably be called any kind of 'pure'? It's not pure at all. The function returns a completely different result when called twice. That's the definition of not-pure. I

Re: To help LDC/GDC

2013-04-10 Thread Timon Gehr
On 04/11/2013 02:41 AM, Walter Bright wrote: On 4/10/2013 5:33 PM, deadalnix wrote: call with const parameter can be considered strongly pure if the argument is immutable The argument doesn't need to be immutable because nobody can change it while the function is running. (He has written

Re: To help LDC/GDC

2013-04-10 Thread Timon Gehr
On 04/10/2013 11:50 PM, Walter Bright wrote: ... My point was that competing designs are very probably not necessary. We just need to pull on the string on what must be. Yes, IMO it is quite obvious how to do it. (transfer the meaning of the modifiers from member functions to local

Re: To help LDC/GDC

2013-04-10 Thread Walter Bright
On 4/10/2013 10:44 PM, Timon Gehr wrote: On 04/10/2013 11:50 PM, Walter Bright wrote: ... My point was that competing designs are very probably not necessary. We just need to pull on the string on what must be. Yes, IMO it is quite obvious how to do it. (transfer the meaning of the

Re: To help LDC/GDC

2013-04-09 Thread Jacob Carlborg
On 2013-04-09 05:30, Walter Bright wrote: In C++, it is legal to cast away const and mutate it. That is undefined behavior in D. Didn't they change how const behaves in C++11, I'm thinking of this: http://channel9.msdn.com/posts/C-and-Beyond-2012-Herb-Sutter-You-dont-know-blank-and-blank --

Re: To help LDC/GDC

2013-04-09 Thread Manu
On 9 April 2013 01:07, Jacob Carlborg d...@me.com wrote: On 2013-04-08 14:52, Iain Buclaw wrote: On 8 April 2013 13:25, Jacob Carlborg d...@me.com mailto:d...@me.com wrote: On 2013-04-08 10:29, Iain Buclaw wrote: This information could possibly be helpful. Though given that

Re: To help LDC/GDC

2013-04-09 Thread Manu
On 9 April 2013 01:40, Iain Buclaw ibuc...@ubuntu.com wrote: On 8 April 2013 13:37, Manu turkey...@gmail.com wrote: Oh my god... . this is the most upsetting thing I've heard all day! :( No really, I have been S excited for so long about this optimisation potential in D! There's

Re: To help LDC/GDC

2013-04-09 Thread Manu
On 9 April 2013 13:30, Walter Bright newshou...@digitalmars.com wrote: On 4/8/2013 5:39 AM, Manu wrote: But D makes no further guarantee. I don't see how const in D is any different than const in C++ in that sense? That's basically the concept of const, it's not a useful concept for

Re: To help LDC/GDC

2013-04-09 Thread Dicebot
On Tuesday, 9 April 2013 at 07:11:02 UTC, Jacob Carlborg wrote: On 2013-04-09 05:30, Walter Bright wrote: In C++, it is legal to cast away const and mutate it. That is undefined behavior in D. Didn't they change how const behaves in C++11, I'm thinking of this:

Re: To help LDC/GDC

2013-04-09 Thread Dicebot
On Tuesday, 9 April 2013 at 07:52:20 UTC, Manu wrote: But that's meaningless though, because there's always the possibility that something somewhere else may have a non-const reference to that thing. Can you suggest a case where const could EVER be used in any sort of optimisation? I don't

Re: To help LDC/GDC

2013-04-09 Thread Manu
On 9 April 2013 14:39, Walter Bright newshou...@digitalmars.com wrote: On 4/8/2013 5:37 AM, Manu wrote: Only builtins are pure in the sense of 'C'. Even functions considered PUREstrong by the frontend may update an internal state, so the rules just don't apply. Except for

Re: To help LDC/GDC

2013-04-09 Thread Dicebot
On Tuesday, 9 April 2013 at 07:41:55 UTC, Manu wrote: How does one specify that in their code? Is 'strong pure' a keyword? You can't and this is the most stupid thing about pure in D. Compiler can detect which one it is, but you can't force it to accept pure only as strong pure.

Re: To help LDC/GDC

2013-04-09 Thread Manu
On 9 April 2013 17:54, Dicebot m.stras...@gmail.com wrote: On Tuesday, 9 April 2013 at 07:52:20 UTC, Manu wrote: But that's meaningless though, because there's always the possibility that something somewhere else may have a non-const reference to that thing. Can you suggest a case where

Re: To help LDC/GDC

2013-04-09 Thread Dicebot
On Tuesday, 9 April 2013 at 08:00:38 UTC, Manu wrote: Errrm, only globals are shared by default. Locals or allocated memory are not thread-local, can be passed wherever they want, including other threads. No, globals are also thread-local by default. Everything is. And it was intended that

Re: To help LDC/GDC

2013-04-09 Thread Dicebot
On Tuesday, 9 April 2013 at 07:57:37 UTC, Manu wrote: Are you saying the example above is not actually valid code? struct Foo { int a = 0; pure int bar( int n ) { // Weakly pure a += n; return a; } } That's not pure. Call it twice with the same args, you'll

Re: To help LDC/GDC

2013-04-09 Thread Zach the Mystic
On Tuesday, 9 April 2013 at 07:57:37 UTC, Manu wrote: Are you saying the example above is not actually valid code? struct Foo { int a = 0; pure int bar( int n ) { // Weakly pure a += n; return a; } } That's not pure. Call it twice with the same args, you'll

Re: To help LDC/GDC

2013-04-09 Thread Manu
On 9 April 2013 18:03, Dicebot m.stras...@gmail.com wrote: On Tuesday, 9 April 2013 at 08:00:38 UTC, Manu wrote: Errrm, only globals are shared by default. Locals or allocated memory are not thread-local, can be passed wherever they want, including other threads. No, globals are also

Re: To help LDC/GDC

2013-04-09 Thread Manu
On 9 April 2013 18:04, Dicebot m.stras...@gmail.com wrote: On Tuesday, 9 April 2013 at 07:57:37 UTC, Manu wrote: Are you saying the example above is not actually valid code? struct Foo { int a = 0; pure int bar( int n ) { // Weakly pure a += n; return a; } }

Re: To help LDC/GDC

2013-04-09 Thread Simen Kjærås
On Tue, 09 Apr 2013 09:41:43 +0200, Manu turkey...@gmail.com wrote: How does one specify that in their code? Is 'strong pure' a keyword? It's not a keyword. It's inferred by the compiler when a function is marked pure (or is a template function and is inferred pure), and all parameters are

Re: To help LDC/GDC

2013-04-09 Thread Dicebot
On Tuesday, 9 April 2013 at 08:31:06 UTC, Manu wrote: E, no? Only globals are thread-local. Everything else is either stack or heap allocated. Well, stack is also thread-local, isn't it? ;) Heap objection accepted. Yes but that's ultimately useless. If sharing is undefined, and you

Re: To help LDC/GDC

2013-04-09 Thread Simen Kjærås
On Tue, 09 Apr 2013 10:33:45 +0200, Manu turkey...@gmail.com wrote: On 9 April 2013 18:04, Dicebot m.stras...@gmail.com wrote: On Tuesday, 9 April 2013 at 07:57:37 UTC, Manu wrote: Are you saying the example above is not actually valid code? struct Foo { int a = 0; pure int bar(

Re: To help LDC/GDC

2013-04-09 Thread Dicebot
On Tuesday, 9 April 2013 at 08:33:53 UTC, Manu wrote: How can 'weak pure' reasonably be called any kind of 'pure'? It's not pure at all. The function returns a completely different result when called twice. That's the definition of not-pure. I suggest that no D language newbie would ever

Re: To help LDC/GDC

2013-04-09 Thread Joseph Rushton Wakeling
On 04/09/2013 09:56 AM, Dicebot wrote: You can't and this is the most stupid thing about pure in D. Compiler can detect which one it is, but you can't force it to accept pure only as strong pure. This is surely not so terrible -- it leaves the door open for a new keyword (strong pure

Re: To help LDC/GDC

2013-04-09 Thread Joseph Rushton Wakeling
On 04/08/2013 08:14 PM, Simen Kjaeraas wrote: Like others have stated, it's so you can do this: struct Foo { int a = 0; pure int bar( int n ) { // Weakly pure a += n; return a; } } pure int Baz( int n ) { // Strongly pure Foo foo; return foo.bar( n );

Re: To help LDC/GDC

2013-04-09 Thread Timon Gehr
On 04/09/2013 05:30 AM, Walter Bright wrote: On 4/8/2013 5:39 AM, Manu wrote: But D makes no further guarantee. I don't see how const in D is any different than const in C++ in that sense? That's basically the concept of const, it's not a useful concept for optimisation, only immutable is. In

Re: To help LDC/GDC

2013-04-09 Thread Artur Skawina
On 04/09/13 02:44, deadalnix wrote: On Monday, 8 April 2013 at 15:07:31 UTC, Jacob Carlborg wrote: I though that wasn't possible. What's the point of pure if that's possible? You have to think that this is an hidden parameter. The function touch that parameter, no global state. D's pure is

Re: To help LDC/GDC

2013-04-09 Thread Timon Gehr
On 04/09/2013 10:33 AM, Manu wrote: ... How can 'weak pure' reasonably be called any kind of 'pure'? It's not pure at all. The function returns a completely different result when called twice. That's the definition of not-pure. (Actually this is not the definition of impure.) In D, 'pure'

Re: To help LDC/GDC

2013-04-09 Thread Manu
On 9 April 2013 19:43, Joseph Rushton Wakeling joseph.wakel...@webdrake.net wrote: On 04/08/2013 08:14 PM, Simen Kjaeraas wrote: Like others have stated, it's so you can do this: struct Foo { int a = 0; pure int bar( int n ) { // Weakly pure a += n; return a;

Re: To help LDC/GDC

2013-04-09 Thread Timon Gehr
On 04/09/2013 12:13 PM, Artur Skawina wrote: ... D's pure is horribly misnamed; nobody that's not already aware of the D re-definition expects pure to mean what it currently does. struct S { int* p; int f() pure @safe nothrow { return ++*p; } } int i = 1; int

Re: To help LDC/GDC

2013-04-09 Thread David Nadlinger
On Tuesday, 9 April 2013 at 10:28:16 UTC, Manu wrote: There's nothing 'pure' about a function that has side effects. It's a totally different concept, and should be named appropriately. It's not totally different – the possible side effects are still very localized and controllable by the

Re: To help LDC/GDC

2013-04-09 Thread deadalnix
On Tuesday, 9 April 2013 at 03:36:28 UTC, Walter Bright wrote: On 4/8/2013 5:39 AM, Manu wrote: But D makes no further guarantee. I don't see how const in D is any different than const in C++ in that sense? That's basically the concept of const, it's not a useful concept for optimisation,

Re: To help LDC/GDC

2013-04-09 Thread kenji hara
2013/4/9 Timon Gehr timon.g...@gmx.ch On 04/09/2013 12:13 PM, Artur Skawina wrote: [snip] That's not pure by any definition, I'd counter that it is pure by the D definition. I completely agree with Timon. It's the definition in D. The meaning of 'pure' keyword in D *contains* widely

Re: To help LDC/GDC

2013-04-09 Thread Joseph Rushton Wakeling
On 04/09/2013 12:28 PM, Manu wrote: There's nothing 'pure' about a function that has side effects. It's a totally different concept, and should be named appropriately. But a natural way to define a pseudo-random number generator is a combination of a state variable together with a pure function

Re: To help LDC/GDC

2013-04-09 Thread Timon Gehr
On 04/09/2013 12:28 PM, Manu wrote: ... There's nothing 'pure' about a function that has side effects. If it has the same side effects every time it is called with the same arguments, then there is something pure about it. It's a totally different concept, The concept of mutation can be

Re: To help LDC/GDC

2013-04-09 Thread Daniel Murphy
deadalnix deadal...@gmail.com wrote in message news:yhvwbephdechjxvrk...@forum.dlang.org... No, D have holes in its type system and so can't ensure anything. It has been show many many many times, especially by Timon and myself, and I'm kind of fed up to have to repeat that again and again,

Re: To help LDC/GDC

2013-04-09 Thread deadalnix
On Tuesday, 9 April 2013 at 10:57:20 UTC, Daniel Murphy wrote: deadalnix deadal...@gmail.com wrote in message news:yhvwbephdechjxvrk...@forum.dlang.org... No, D have holes in its type system and so can't ensure anything. It has been show many many many times, especially by Timon and myself,

Re: To help LDC/GDC

2013-04-09 Thread Artur Skawina
On 04/09/13 12:51, kenji hara wrote: 2013/4/9 Timon Gehr timon.g...@gmx.ch mailto:timon.g...@gmx.ch On 04/09/2013 12:13 PM, Artur Skawina wrote: [snip] That's not pure by any definition, I'd counter that it is pure by the D definition. I completely agree with

Re: To help LDC/GDC

2013-04-09 Thread Timon Gehr
On 04/09/2013 12:57 PM, Daniel Murphy wrote: deadalnix deadal...@gmail.com wrote in message news:yhvwbephdechjxvrk...@forum.dlang.org... No, D have holes in its type system and so can't ensure anything. It has been show many many many times, especially by Timon and myself, and I'm kind of fed

Re: To help LDC/GDC

2013-04-09 Thread Manu
On 9 April 2013 20:50, Timon Gehr timon.g...@gmx.ch wrote: On 04/09/2013 12:28 PM, Manu wrote: ... There's nothing 'pure' about a function that has side effects. If it has the same side effects every time it is called with the same arguments, then there is something pure about it. But

Re: To help LDC/GDC

2013-04-09 Thread Manu
On 9 April 2013 20:57, Daniel Murphy yebbl...@nospamgmail.com wrote: deadalnix deadal...@gmail.com wrote in message news:yhvwbephdechjxvrk...@forum.dlang.org... No, D have holes in its type system and so can't ensure anything. It has been show many many many times, especially by Timon and

Re: To help LDC/GDC

2013-04-09 Thread tn
On Tuesday, 9 April 2013 at 08:33:53 UTC, Manu wrote: On 9 April 2013 18:04, Dicebot m.stras...@gmail.com wrote: On Tuesday, 9 April 2013 at 07:57:37 UTC, Manu wrote: Are you saying the example above is not actually valid code? struct Foo { int a = 0; pure int bar( int n ) { //

Re: To help LDC/GDC

2013-04-09 Thread Jacob Carlborg
On 2013-04-09 12:24, Timon Gehr wrote: static - (no suggestion) static has quite a lot of overloads as well. -- /Jacob Carlborg

Re: To help LDC/GDC

2013-04-09 Thread Timon Gehr
On 04/09/2013 01:27 PM, Manu wrote: ... The only optimisation possibility is for strong pure functions that are also nothrow, right? Was that the conditions for pure function refactoring? No, strongly pure functions will always throw the same classes of exceptions when called with the same

Re: To help LDC/GDC

2013-04-09 Thread Timon Gehr
On 04/09/2013 01:39 PM, Timon Gehr wrote: On 04/09/2013 01:27 PM, Manu wrote: ... The only optimisation possibility is for strong pure functions that are also nothrow, right? Was that the conditions for pure function refactoring? No, strongly pure functions will always throw the same

Re: To help LDC/GDC

2013-04-09 Thread Simen Kjærås
On Tue, 09 Apr 2013 13:10:16 +0200, Artur Skawina art.08...@gmail.com wrote: A function that both directly depends on global mutable state (and modifies it) can hardly be called pure. Can you (anybody) give a D pure definition that allows for the program that I've posted and still makes pure

Re: To help LDC/GDC

2013-04-09 Thread ixid
On Tuesday, 9 April 2013 at 10:24:45 UTC, Timon Gehr wrote: On 04/09/2013 10:33 AM, Manu wrote: ... How can 'weak pure' reasonably be called any kind of 'pure'? It's not pure at all. The function returns a completely different result when called twice. That's the definition of not-pure.

Re: To help LDC/GDC

2013-04-09 Thread Timon Gehr
On 04/09/2013 01:26 PM, Manu wrote: On 9 April 2013 20:50, Timon Gehr timon.g...@gmx.ch mailto:timon.g...@gmx.ch wrote: On 04/09/2013 12:28 PM, Manu wrote: ... There's nothing 'pure' about a function that has side effects. If it has the same side effects every time

Re: To help LDC/GDC

2013-04-09 Thread Timon Gehr
On 04/09/2013 01:47 PM, Simen Kjærås wrote: On Tue, 09 Apr 2013 13:10:16 +0200, Artur Skawina art.08...@gmail.com wrote: A function that both directly depends on global mutable state (and modifies it) can hardly be called pure. Can you (anybody) give a D pure definition that allows for the

Re: To help LDC/GDC

2013-04-09 Thread David Nadlinger
On Tuesday, 9 April 2013 at 11:26:38 UTC, Manu wrote: But it doesn't. It could do anything when called a second time, same arguments or not. Can it? David

Re: To help LDC/GDC

2013-04-09 Thread Manu
On 9 April 2013 21:30, tn n...@email.com wrote: On Tuesday, 9 April 2013 at 08:33:53 UTC, Manu wrote: On 9 April 2013 18:04, Dicebot m.stras...@gmail.com wrote: On Tuesday, 9 April 2013 at 07:57:37 UTC, Manu wrote: Are you saying the example above is not actually valid code? struct Foo

Re: To help LDC/GDC

2013-04-09 Thread Andrei Alexandrescu
On 4/9/13 3:56 AM, Manu wrote: Are you saying the example above is not actually valid code? struct Foo { int a = 0; pure int bar( int n ) { // Weakly pure a += n; return a; } } That's not pure. Call it twice with the same args, you'll different answers. The

  1   2   >