Re: What to do about default function arguments

2012-04-26 Thread Maxim Fomin
On Thursday, 26 April 2012 at 03:44:27 UTC, Walter Bright wrote: A subtle but nasty problem - are default arguments part of the type, or part of the declaration? See http://d.puremagic.com/issues/show_bug.cgi?id=3866 Currently, they are both, which leads to the nasty behavior in the bug

Re: What to do about default function arguments

2012-04-26 Thread Timon Gehr
On 04/26/2012 05:44 AM, Walter Bright wrote: A subtle but nasty problem - are default arguments part of the type, or part of the declaration? See http://d.puremagic.com/issues/show_bug.cgi?id=3866 Currently, they are both, That is how it should be. which leads to the nasty behavior in the

Re: What to do about default function arguments

2012-04-26 Thread Walter Bright
On 4/26/2012 12:47 AM, Timon Gehr wrote: On 04/26/2012 05:44 AM, Walter Bright wrote: A subtle but nasty problem - are default arguments part of the type, or part of the declaration? See http://d.puremagic.com/issues/show_bug.cgi?id=3866 Currently, they are both, That is how it should be.

Re: What to do about default function arguments

2012-04-26 Thread Don Clugston
On 26/04/12 05:44, Walter Bright wrote: A subtle but nasty problem - are default arguments part of the type, or part of the declaration? See http://d.puremagic.com/issues/show_bug.cgi?id=3866 Currently, they are both, which leads to the nasty behavior in the bug report. The problem centers

Re: What to do about default function arguments

2012-04-26 Thread Jacob Carlborg
On 2012-04-26 05:44, Walter Bright wrote: But if we make default arguments solely a part of the function declaration, then function pointers (and delegates) cannot have default arguments. (And maybe this isn't a bad thing?) Why not? -- /Jacob Carlborg

Re: What to do about default function arguments

2012-04-26 Thread Timon Gehr
On 04/26/2012 09:54 AM, Walter Bright wrote: On 4/26/2012 12:47 AM, Timon Gehr wrote: On 04/26/2012 05:44 AM, Walter Bright wrote: A subtle but nasty problem - are default arguments part of the type, or part of the declaration? See http://d.puremagic.com/issues/show_bug.cgi?id=3866

Re: What to do about default function arguments

2012-04-26 Thread Timon Gehr
On 04/26/2012 10:51 AM, Don Clugston wrote: On 26/04/12 05:44, Walter Bright wrote: A subtle but nasty problem - are default arguments part of the type, or part of the declaration? See http://d.puremagic.com/issues/show_bug.cgi?id=3866 Currently, they are both, which leads to the nasty

Re: What to do about default function arguments

2012-04-26 Thread Don Clugston
On 26/04/12 11:28, Timon Gehr wrote: On 04/26/2012 10:51 AM, Don Clugston wrote: On 26/04/12 05:44, Walter Bright wrote: A subtle but nasty problem - are default arguments part of the type, or part of the declaration? See http://d.puremagic.com/issues/show_bug.cgi?id=3866 Currently, they are

Re: What to do about default function arguments

2012-04-26 Thread Don Clugston
On 26/04/12 11:21, Timon Gehr wrote: On 04/26/2012 09:54 AM, Walter Bright wrote: On 4/26/2012 12:47 AM, Timon Gehr wrote: On 04/26/2012 05:44 AM, Walter Bright wrote: A subtle but nasty problem - are default arguments part of the type, or part of the declaration? See

Re: What to do about default function arguments

2012-04-26 Thread Timon Gehr
On 04/26/2012 11:46 AM, Don Clugston wrote: On 26/04/12 11:28, Timon Gehr wrote: On 04/26/2012 10:51 AM, Don Clugston wrote: On 26/04/12 05:44, Walter Bright wrote: A subtle but nasty problem - are default arguments part of the type, or part of the declaration? See

Re: What to do about default function arguments

2012-04-26 Thread Timon Gehr
On 04/26/2012 11:54 AM, Don Clugston wrote: On 26/04/12 11:21, Timon Gehr wrote: On 04/26/2012 09:54 AM, Walter Bright wrote: On 4/26/2012 12:47 AM, Timon Gehr wrote: On 04/26/2012 05:44 AM, Walter Bright wrote: A subtle but nasty problem - are default arguments part of the type, or part of

Re: What to do about default function arguments

2012-04-26 Thread Don Clugston
On 26/04/12 12:11, Timon Gehr wrote: On 04/26/2012 11:46 AM, Don Clugston wrote: On 26/04/12 11:28, Timon Gehr wrote: On 04/26/2012 10:51 AM, Don Clugston wrote: On 26/04/12 05:44, Walter Bright wrote: A subtle but nasty problem - are default arguments part of the type, or part of the

Re: What to do about default function arguments

2012-04-26 Thread Trass3r
I've always thought of default arguments to be plain syntactic sugar, so for void f(int i, int j=5)f(1) is simply transformed to f(1,5) and the rest is the same.

Re: What to do about default function arguments

2012-04-26 Thread Michel Fortin
On 2012-04-26 03:44:07 +, Walter Bright newshou...@digitalmars.com said: A subtle but nasty problem - are default arguments part of the type, or part of the declaration? See http://d.puremagic.com/issues/show_bug.cgi?id=3866 Currently, they are both, which leads to the nasty behavior

Re: What to do about default function arguments

2012-04-26 Thread deadalnix
Le 26/04/2012 05:44, Walter Bright a écrit : A subtle but nasty problem - are default arguments part of the type, or part of the declaration? See http://d.puremagic.com/issues/show_bug.cgi?id=3866 Currently, they are both, which leads to the nasty behavior in the bug report. The problem

Re: What to do about default function arguments

2012-04-26 Thread bearophile
Walter: A subtle but nasty problem - are default arguments part of the type, or part of the declaration? I'm waiting for years to see you finally facing this problem too :-) The current situation is not acceptable, so some change of the current situation is required, probably a small

Re: What to do about default function arguments

2012-04-26 Thread bearophile
Michel Fortin: That said, there was some talk about adding support for named parameters a year ago. Good reminder. I think such parts of D shouldn't be designed one of a time. If you want to face the problem of default arguments, it's better to think about named arguments too (even if you

Re: What to do about default function arguments

2012-04-26 Thread Steven Schveighoffer
On Wed, 25 Apr 2012 23:44:07 -0400, Walter Bright newshou...@digitalmars.com wrote: A subtle but nasty problem - are default arguments part of the type, or part of the declaration? See http://d.puremagic.com/issues/show_bug.cgi?id=3866 Currently, they are both, which leads to the

Re: What to do about default function arguments

2012-04-26 Thread Joseph Rushton Wakeling
On 26/04/12 05:44, Walter Bright wrote: But if we make default arguments solely a part of the function declaration, then function pointers (and delegates) cannot have default arguments. (And maybe this isn't a bad thing?) I can't see disallowing default arguments as being a good thing. For

Re: What to do about default function arguments

2012-04-26 Thread Steven Schveighoffer
On Thu, 26 Apr 2012 09:08:07 -0400, Steven Schveighoffer schvei...@yahoo.com wrote: void main() { auto a = (int x = 1) { return x;}; pure nothrow @safe int function(int) b = (int x) { return x;}; pragma(msg, typeof(a).stringof); pragma(msg, typeof(b).stringof); b = a;

Re: What to do about default function arguments

2012-04-26 Thread H. S. Teoh
On Wed, Apr 25, 2012 at 10:39:01PM -0700, Walter Bright wrote: On 4/25/2012 10:29 PM, Ary Manzana wrote: I don't understand the relationship between two delegate types being the same and thus sharing the same implementation for default arguments for *different instances* of a delegate with the

Re: What to do about default function arguments

2012-04-26 Thread Sean Kelly
On Apr 25, 2012, at 9:10 PM, Walter Bright newshou...@digitalmars.com wrote: On 4/25/2012 8:44 PM, Walter Bright wrote: The problem centers around name mangling. If two types mangle the same, then they are the same type. But default arguments are not part of the mangled string. Hence the

Re: What to do about default function arguments

2012-04-26 Thread Daniel Murphy
Walter Bright newshou...@digitalmars.com wrote in message news:jnagar$2d8k$1...@digitalmars.com... A subtle but nasty problem - are default arguments part of the type, or part of the declaration? See http://d.puremagic.com/issues/show_bug.cgi?id=3866 Currently, they are both, which leads

Re: What to do about default function arguments

2012-04-26 Thread Jonathan M Davis
On Thursday, April 26, 2012 13:54:47 bearophile wrote: The simplest solution is to the breaking change of disallowing default arguments for function pointers and delegates. This also means disallowing talking the pointer/delegate of function with default arguments. No it doesn't. You could

Re: What to do about default function arguments

2012-04-26 Thread Jonathan M Davis
On Thursday, April 26, 2012 15:09:15 Joseph Rushton Wakeling wrote: On 26/04/12 05:44, Walter Bright wrote: But if we make default arguments solely a part of the function declaration, then function pointers (and delegates) cannot have default arguments. (And maybe this isn't a bad thing?)

Re: What to do about default function arguments

2012-04-26 Thread Joseph Rushton Wakeling
On 26/04/12 19:25, Jonathan M Davis wrote: There is an _enormous_ difference between disallowing default arguments in general and disallowing them in function pointers and delegates. I think maybe I've misunderstood the problem. Are we talking about default values _of the function pointer_

Re: What to do about default function arguments

2012-04-26 Thread Jonathan M Davis
On Thursday, April 26, 2012 19:45:55 Joseph Rushton Wakeling wrote: On 26/04/12 19:25, Jonathan M Davis wrote: There is an _enormous_ difference between disallowing default arguments in general and disallowing them in function pointers and delegates. I think maybe I've misunderstood the

Re: What to do about default function arguments

2012-04-26 Thread Martin Nowak
On Thu, 26 Apr 2012 06:10:14 +0200, Walter Bright newshou...@digitalmars.com wrote: On 4/25/2012 8:44 PM, Walter Bright wrote: The problem centers around name mangling. If two types mangle the same, then they are the same type. But default arguments are not part of the mangled string.

Re: What to do about default function arguments

2012-04-26 Thread Martin Nowak
int function(int) opAddrOf() { return fbody; } That was wrong, this should be supported through implicit conversion.

Re: What to do about default function arguments

2012-04-26 Thread Walter Bright
On 4/26/2012 8:06 AM, Sean Kelly wrote: Sounds to me like you just answered your own question :-) Pretty much. I posted it here to see if I missed something major. Not that that ever happens :-)

Re: What to do about default function arguments

2012-04-26 Thread Walter Bright
On 4/26/2012 2:21 AM, Timon Gehr wrote: This is a matter of terminology. For example, for 'equal' just exclude the default parameters from the comparison. For 'the same' include default parameters in the comparison. (therefore, 'the same' implies 'equal') I think this is torturing the

Re: What to do about default function arguments

2012-04-26 Thread Walter Bright
On 4/26/2012 1:54 AM, Jacob Carlborg wrote: On 2012-04-26 05:44, Walter Bright wrote: But if we make default arguments solely a part of the function declaration, then function pointers (and delegates) cannot have default arguments. (And maybe this isn't a bad thing?) Why not? Because a

Re: What to do about default function arguments

2012-04-26 Thread Timon Gehr
On 04/26/2012 08:56 PM, Walter Bright wrote: On 4/26/2012 2:21 AM, Timon Gehr wrote: This is a matter of terminology. For example, for 'equal' just exclude the default parameters from the comparison. For 'the same' include default parameters in the comparison. (therefore, 'the same' implies

Re: What to do about default function arguments

2012-04-26 Thread deadalnix
Le 26/04/2012 20:49, Walter Bright a écrit : On 4/26/2012 8:06 AM, Sean Kelly wrote: Sounds to me like you just answered your own question :-) Pretty much. I posted it here to see if I missed something major. Not that that ever happens :-) Why does default argument should be mangled at all

Re: What to do about default function arguments

2012-04-26 Thread Manu
I've actually been making fairly extensive use of function/delegate default args. I was pleasantly surprised when I realised it was possible. Funnily enough, It's one of those things that I just expected should work (as I find most things I just expect should work do in fact tend to work in D), so

What to do about default function arguments

2012-04-25 Thread Walter Bright
A subtle but nasty problem - are default arguments part of the type, or part of the declaration? See http://d.puremagic.com/issues/show_bug.cgi?id=3866 Currently, they are both, which leads to the nasty behavior in the bug report. The problem centers around name mangling. If two types

Re: What to do about default function arguments

2012-04-25 Thread Jonathan M Davis
On Wednesday, April 25, 2012 20:44:07 Walter Bright wrote: A subtle but nasty problem - are default arguments part of the type, or part of the declaration? See http://d.puremagic.com/issues/show_bug.cgi?id=3866 Currently, they are both, which leads to the nasty behavior in the bug

Re: What to do about default function arguments

2012-04-25 Thread Nathan M. Swan
On Thursday, 26 April 2012 at 03:44:27 UTC, Walter Bright wrote: A subtle but nasty problem - are default arguments part of the type, or part of the declaration? See http://d.puremagic.com/issues/show_bug.cgi?id=3866 Currently, they are both, which leads to the nasty behavior in the bug

Re: What to do about default function arguments

2012-04-25 Thread Walter Bright
On 4/25/2012 8:44 PM, Walter Bright wrote: The problem centers around name mangling. If two types mangle the same, then they are the same type. But default arguments are not part of the mangled string. Hence the schizophrenic behavior. One might suggest mangling the default argument into the

Re: What to do about default function arguments

2012-04-25 Thread H. S. Teoh
On Wed, Apr 25, 2012 at 08:44:07PM -0700, Walter Bright wrote: A subtle but nasty problem - are default arguments part of the type, or part of the declaration? My intuition suggests they are part of the declaration, but not part of the type. For example, you could have two functions:

Re: What to do about default function arguments

2012-04-25 Thread Walter Bright
On 4/25/2012 9:42 PM, H. S. Teoh wrote: This is bad. What if you have two delegates with different default arguments? What would this code do: auto foo = (int a=1) { return a; }; auto bar = (int a=2) { return a; }; writeln(foo()); writeln(bar()); ? Give you

Re: What to do about default function arguments

2012-04-25 Thread H. S. Teoh
On Wed, Apr 25, 2012 at 10:08:26PM -0700, Walter Bright wrote: On 4/25/2012 9:42 PM, H. S. Teoh wrote: This is bad. What if you have two delegates with different default arguments? What would this code do: auto foo = (int a=1) { return a; }; auto bar = (int a=2) { return a; };

Re: What to do about default function arguments

2012-04-25 Thread Walter Bright
On 4/25/2012 10:20 PM, H. S. Teoh wrote: On Wed, Apr 25, 2012 at 10:08:26PM -0700, Walter Bright wrote: On 4/25/2012 9:42 PM, H. S. Teoh wrote: This is bad. What if you have two delegates with different default arguments? What would this code do: auto foo = (int a=1) { return a; };

Re: What to do about default function arguments

2012-04-25 Thread Ary Manzana
On 4/26/12 11:44 AM, Walter Bright wrote: A subtle but nasty problem - are default arguments part of the type, or part of the declaration? See http://d.puremagic.com/issues/show_bug.cgi?id=3866 Currently, they are both, which leads to the nasty behavior in the bug report. The problem centers

Re: What to do about default function arguments

2012-04-25 Thread Walter Bright
On 4/25/2012 10:29 PM, Ary Manzana wrote: I don't understand the relationship between two delegate types being the same and thus sharing the same implementation for default arguments for *different instances* of a delegate with the same type. Maybe a bug in how it's currently implemented? If