Re: 1 matches bool, 2 matches long

2013-04-25 Thread Timon Gehr
On 04/25/2013 11:05 PM, Ali Çehreli wrote: ... Is bool more specialized than long or is this a bug? Intuitively, both should match the 'long' overload. bool is more specialized than long; you can pass any bool argument as a long argument, but not vice versa. It feels like there should at l

Re: 1 matches bool, 2 matches long

2013-04-25 Thread Simen Kjaeraas
On 2013-04-25, 23:05, Ali Çehreli wrote: This question has first appeared on D.learn: http://forum.dlang.org/post/vlosugoeuobjrdfae...@forum.dlang.org A simple program: import std.stdio; void foo(bool b) { writeln("bool"); } void foo(long l) { writeln("long"); } void main() {

Re: 1 matches bool, 2 matches long

2013-04-25 Thread Walter Bright
Is bool more specialized than long Yes, because a bool can be implicitly converted to a long, but a long cannot be implicitly converted to a bool.

Re: 1 matches bool, 2 matches long

2013-04-25 Thread deadalnix
On Friday, 26 April 2013 at 00:35:33 UTC, Walter Bright wrote: Is bool more specialized than long Yes, because a bool can be implicitly converted to a long, but a long cannot be implicitly converted to a bool. As we have bool literals as true and false, I don't think 1 should match bool in

Re: 1 matches bool, 2 matches long

2013-04-25 Thread bearophile
Is is acceptable for 1 to match bool and 2 long? Maybe it is not acceptable in a serious language with strong typing... Bye, bearophile

Re: 1 matches bool, 2 matches long

2013-04-25 Thread Maxim Fomin
On Thursday, 25 April 2013 at 21:05:43 UTC, Ali Çehreli wrote: This question has first appeared on D.learn: ... The program calls two separate foo() overloads for 1 and 2: bool long According to the language spec, both overloads match the int argument by "implicit conversion" as described un

Re: 1 matches bool, 2 matches long

2013-04-25 Thread Ali Çehreli
On 04/25/2013 06:44 PM, Maxim Fomin wrote: > On Thursday, 25 April 2013 at 21:05:43 UTC, Ali Çehreli wrote: > Looks like value range propagation bug because 1 is integer literal and > should be converted to long. There is no way for 1 to be converted to > bool here That special conversion rule

Re: 1 matches bool, 2 matches long

2013-04-25 Thread Andrej Mitrovic
On 4/26/13, Ali Çehreli wrote: > Introduce a variable: > >int i = 1; >foo(i); // again, goes to long An even better example: enum e = 1; void main() { foo(e); // bool } static e = 1; void main() { foo(e); // long } I find this unacceptable.

Re: 1 matches bool, 2 matches long

2013-04-25 Thread Jonathan M Davis
On Thursday, April 25, 2013 17:35:34 Walter Bright wrote: > > Is bool more specialized than long > > Yes, because a bool can be implicitly converted to a long, but a long cannot > be implicitly converted to a bool. However, given that bool isn't even an integral type, it seems very wrong that it

Re: 1 matches bool, 2 matches long

2013-04-25 Thread Kapps
This is just silly. Changing enum defaultVal = 1 to defaultVal = 2 should never result in calling a different overload.

Re: 1 matches bool, 2 matches long

2013-04-25 Thread deadalnix
On Friday, 26 April 2013 at 02:29:07 UTC, Jonathan M Davis wrote: On Thursday, April 25, 2013 17:35:34 Walter Bright wrote: > Is bool more specialized than long Yes, because a bool can be implicitly converted to a long, but a long cannot be implicitly converted to a bool. However, given tha

Re: 1 matches bool, 2 matches long

2013-04-25 Thread Walter Bright
On 4/25/2013 7:54 PM, Kapps wrote: This is just silly. Changing enum defaultVal = 1 to defaultVal = 2 should never result in calling a different overload. This does: import core.stdc.stdio; enum x = 1; enum y = 4; int foo(short s) { return 1; } int foo(long s

Re: 1 matches bool, 2 matches long

2013-04-25 Thread Ali Çehreli
On 04/25/2013 10:02 PM, Walter Bright wrote:> On 4/25/2013 7:54 PM, Kapps wrote: >> This is just silly. >> Changing enum defaultVal = 1 to defaultVal = 2 should never result in >> calling a >> different overload. > > This does: > > > import core.stdc.stdio; > > enum x = 1

Re: 1 matches bool, 2 matches long

2013-04-25 Thread Walter Bright
On 4/25/2013 10:49 PM, Ali Çehreli wrote: It certainly behaves that way but it isn't an integer type and that's why it is unintuitive. But it is an integer type. bool is a type with two values: false and true with the following conversion rules: false -> 0 true -> 1 0 value -> false non-zer

Re: 1 matches bool, 2 matches long

2013-04-25 Thread deadalnix
On Friday, 26 April 2013 at 05:02:50 UTC, Walter Bright wrote: On 4/25/2013 7:54 PM, Kapps wrote: This is just silly. Changing enum defaultVal = 1 to defaultVal = 2 should never result in calling a different overload. This does: import core.stdc.stdio; enum x = 100

Re: 1 matches bool, 2 matches long

2013-04-25 Thread deadalnix
On Friday, 26 April 2013 at 06:01:27 UTC, Walter Bright wrote: The real issue is do you want to have the implicit conversions: 0 => false 1 => true or would you require a cast? Yes.

Re: 1 matches bool, 2 matches long

2013-04-25 Thread Manipulator
On Friday, 26 April 2013 at 06:18:29 UTC, deadalnix wrote: On Friday, 26 April 2013 at 06:01:27 UTC, Walter Bright wrote: The real issue is do you want to have the implicit conversions: 0 => false 1 => true or would you require a cast? Yes. +1 What about the implicit conversion for the ot

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Maxim Fomin
On Friday, 26 April 2013 at 02:13:03 UTC, Ali Çehreli wrote: On 04/25/2013 06:44 PM, Maxim Fomin wrote: > On Thursday, 25 April 2013 at 21:05:43 UTC, Ali Çehreli wrote: > Looks like value range propagation bug because 1 is integer literal and > should be converted to long. There is no way for 1

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Maxim Fomin
On Friday, 26 April 2013 at 06:01:27 UTC, Walter Bright wrote: On 4/25/2013 10:49 PM, Ali Çehreli wrote: It certainly behaves that way but it isn't an integer type and that's why it is unintuitive. But it is an integer type. Regarding bool type as integer type is C atavism and should be a

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Mehrdad
On Friday, 26 April 2013 at 06:16:29 UTC, deadalnix wrote: On Friday, 26 April 2013 at 05:02:50 UTC, Walter Bright wrote: A bool is an integer with the range 0..1 This "feature" never has been useful to me. +1

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Walter Bright
On 4/25/2013 11:42 PM, Manipulator wrote: What about the implicit conversion for the other types? I could imagine that they could cause similar bugs. Why not get rid of the implicit conversion? Implicit conversions make the menagerie of integer types tractable. Explicit casts are a sledgehamme

Re: 1 matches bool, 2 matches long

2013-04-26 Thread deadalnix
On Friday, 26 April 2013 at 06:42:28 UTC, Manipulator wrote: On Friday, 26 April 2013 at 06:18:29 UTC, deadalnix wrote: On Friday, 26 April 2013 at 06:01:27 UTC, Walter Bright wrote: The real issue is do you want to have the implicit conversions: 0 => false 1 => true or would you require a c

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Walter Bright
On 4/25/2013 11:16 PM, deadalnix wrote: This "feature" never has been useful to me. It has been useful to me. So there! It has caused bug. The bug is not providing an overload for int. Additionally, the behavior is inconsistent : int i = 1; foo(i); // Don't call the bool version. It is

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Walter Bright
On 4/26/2013 12:07 AM, Maxim Fomin wrote: Regarding bool type as integer type is C atavism and should be abandoned. There's a very lng history of 0 being regarded as false and 1 as true - it goes well beyond C. This leads to comic sitatuation presented in the thread when changing litera

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Maxim Fomin
On Friday, 26 April 2013 at 08:00:28 UTC, Walter Bright wrote: On 4/26/2013 12:07 AM, Maxim Fomin wrote: Regarding bool type as integer type is C atavism and should be abandoned. There's a very lng history of 0 being regarded as false and 1 as true - it goes well beyond C. This should b

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Walter Bright
On 4/26/2013 1:14 AM, Maxim Fomin wrote: I argue the correct solution is to call integer function with integer parameter when integer value is passed. I'm sorry, but that's an assertion not an argument. The other issue with your assertion, as I explained to Ali, is that D does not have a noti

Re: 1 matches bool, 2 matches long

2013-04-26 Thread deadalnix
On Friday, 26 April 2013 at 08:03:14 UTC, Walter Bright wrote: On 4/25/2013 11:16 PM, deadalnix wrote: This "feature" never has been useful to me. It has been useful to me. So there! It has caused bug. The bug is not providing an overload for int. Additionally, the behavior is inconsiste

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Minas Mina
On Friday, 26 April 2013 at 06:01:27 UTC, Walter Bright wrote: On 4/25/2013 10:49 PM, Ali Çehreli wrote: It certainly behaves that way but it isn't an integer type and that's why it is unintuitive. But it is an integer type. It is an integral type _internally_. A bool type should have the v

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Robert Schadek
On 04/26/2013 07:02 AM, Walter Bright wrote: > A bool is an integer with the range 0..1 This is True for the type but for the actual code it looks different. There 0 == false. and everything else is true. import std.stdio; void main() { if(10) { writefln("%d is also true", 10); } }

Re: 1 matches bool, 2 matches long

2013-04-26 Thread ixid
And indeed they do. I did face some very weird bugs caused by that already. What sort of bugs has it caused for you? Just interested, not questioning whether or not it's a source of bugs.

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Paulo Pinto
On Friday, 26 April 2013 at 08:00:28 UTC, Walter Bright wrote: On 4/26/2013 12:07 AM, Maxim Fomin wrote: Regarding bool type as integer type is C atavism and should be abandoned. There's a very lng history of 0 being regarded as false and 1 as true - it goes well beyond C. Assembly, P

Re: 1 matches bool, 2 matches long

2013-04-26 Thread deadalnix
On Friday, 26 April 2013 at 12:34:55 UTC, ixid wrote: And indeed they do. I did face some very weird bugs caused by that already. What sort of bugs has it caused for you? Just interested, not questioning whether or not it's a source of bugs. The last time I experienced that feature was with

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Rob T
On Friday, 26 April 2013 at 08:03:14 UTC, Walter Bright wrote: On 4/25/2013 11:16 PM, deadalnix wrote: This "feature" never has been useful to me. It has been useful to me. So there! If you want an int to behave like a bool, then by all means go ahead and write the code yourself, I don't w

Re: 1 matches bool, 2 matches long

2013-04-26 Thread deadalnix
On Friday, 26 April 2013 at 08:00:28 UTC, Walter Bright wrote: On 4/26/2013 12:07 AM, Maxim Fomin wrote: Regarding bool type as integer type is C atavism and should be abandoned. There's a very lng history of 0 being regarded as false and 1 as true - it goes well beyond C. That is tru

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Ali Çehreli
On 04/26/2013 12:03 AM, Maxim Fomin wrote: > On Friday, 26 April 2013 at 02:13:03 UTC, Ali Çehreli wrote: >> On 04/25/2013 06:44 PM, Maxim Fomin wrote: >> >> > On Thursday, 25 April 2013 at 21:05:43 UTC, Ali Çehreli wrote: >> >> > Looks like value range propagation bug because 1 is integer >> lite

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Walter Bright
On 4/26/2013 6:51 AM, deadalnix wrote: The last time I experienced that feature was with a char getting casted to bool implicitly and then appended to a string, causing super weird behavior after when using the resulting (corrupted) string. void main() { bool b = 'c'; } dmd -c foo foo.d(4

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Walter Bright
On 4/26/2013 5:01 AM, Robert Schadek wrote: Anyway, I think no implicit casts would be wonderful, sure everybody would hate it at first but than... I've used a language with no implicit casts. It didn't get better, and I have an enduring dislike of it.

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Walter Bright
On 4/26/2013 7:33 AM, deadalnix wrote: On Friday, 26 April 2013 at 08:00:28 UTC, Walter Bright wrote: On 4/26/2013 12:07 AM, Maxim Fomin wrote: Regarding bool type as integer type is C atavism and should be abandoned. There's a very lng history of 0 being regarded as false and 1 as true -

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Jonathan M Davis
On Thursday, April 25, 2013 23:01:30 Walter Bright wrote: > On 4/25/2013 10:49 PM, Ali Çehreli wrote: > > It certainly behaves that way but it isn't an integer type and that's why > > it is unintuitive. > > But it is an integer type. That was one of C's big mistakes. There's nothing whatsoever ab

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Timon Gehr
On 04/26/2013 09:11 PM, Walter Bright wrote: On 4/26/2013 5:01 AM, Robert Schadek wrote: Anyway, I think no implicit casts would be wonderful, sure everybody would hate it at first but than... I've used a language with no implicit casts. It didn't get better, and I have an enduring dislike of

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Rob T
On Friday, 26 April 2013 at 19:37:48 UTC, Jonathan M Davis wrote: The main place where casting would be annoying - if conditions and loop conditions - already insert an explicit cast underneat the hood. IMO it still makes no sense to have the implicit casting done in conditional statements be

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Andrej Mitrovic
On 4/26/13, Andrej Mitrovic wrote: > An even better example: import std.stdio; void foo(bool x) { writeln("1"); } void foo(long x) { writeln("2"); } void main() { foo(1); // "1" foo(false ? 2 : 1); // "2" } Kill it with fire.

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Walter Bright
On 4/26/2013 1:16 PM, Timon Gehr wrote: On 04/26/2013 09:11 PM, Walter Bright wrote: On 4/26/2013 5:01 AM, Robert Schadek wrote: Anyway, I think no implicit casts would be wonderful, sure everybody would hate it at first but than... I've used a language with no implicit casts. It didn't get b

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Diggory
Whatever the choices are of whether bool is a 1-bit integer or a a logical true/false value, this should not happen: enum e = 1; void main() { foo(e); // bool } static e = 1; void main() { foo(e); // long } The reason being that according to the language spec, the constant "1" should b

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Brian Schott
On Friday, 26 April 2013 at 06:01:27 UTC, Walter Bright wrote: The real issue is do you want to have the implicit conversions: 0 => false 1 => true or would you require a cast? The idea of a "true number" and a "false number" doesn't make sense, so yes.

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Walter Bright
On 4/26/2013 12:37 PM, Jonathan M Davis wrote: There's nothing whatsoever about bool that makes sense as an integral type. This is where our perspectives sharply diverge. A bool is a 1 bit integer type. Take a look at this, for example: http://d.puremagic.com/issues/show_bug.cgi?id=9963 Mat

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Andrej Mitrovic
On Friday, 26 April 2013 at 21:14:54 UTC, Walter Bright wrote: A bool is a 1 bit integer type. .sizeof returns bytes, not bits, and says that bool is of size 1.

Re: 1 matches bool, 2 matches long

2013-04-26 Thread eles
On Friday, 26 April 2013 at 21:14:54 UTC, Walter Bright wrote: On 4/26/2013 12:37 PM, Jonathan M Davis wrote: There's nothing whatsoever about bool that makes sense as an integral type. This is where our perspectives sharply diverge. A bool is a 1 bit integer type. Take a look at this, for ex

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Tove
On Friday, 26 April 2013 at 21:01:17 UTC, Brian Schott wrote: On Friday, 26 April 2013 at 06:01:27 UTC, Walter Bright wrote: The real issue is do you want to have the implicit conversions: 0 => false 1 => true or would you require a cast? The idea of a "true number" and a "false number" does

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Walter Bright
On 4/26/2013 1:59 PM, Diggory wrote: The actual value shouldn't be taken into account when determining which overload to call, only the type should matter, D has an interesting feature called VRP (value range propagation), where implicit conversion very much depends on the value. For example:

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Walter Bright
On 4/26/2013 1:59 PM, Andrej Mitrovic wrote: On 4/26/13, Andrej Mitrovic wrote: An even better example: import std.stdio; void foo(bool x) { writeln("1"); } void foo(long x) { writeln("2"); } void main() { foo(1); // "1" foo(false ? 2 : 1); // "2" } Kill it with fire. How abo

Re: 1 matches bool, 2 matches long

2013-04-26 Thread eles
On Friday, 26 April 2013 at 21:32:32 UTC, Tove wrote: On Friday, 26 April 2013 at 21:01:17 UTC, Brian Schott wrote: On Friday, 26 April 2013 at 06:01:27 UTC, Walter Bright wrote: Sometimes due to bad coding standards I´m forced to write... if((.long expression with not immediately apparent

Re: 1 matches bool, 2 matches long

2013-04-26 Thread bearophile
Tove: Sometimes due to bad coding standards I´m forced to write... if((.long expression with not immediately apparent operator precedence)!=0) ... absolutely appalling, kills readability with extra () etc. I think here people are not asking to disallow that. A 0 and 1 can be false and t

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Jonathan M Davis
On Friday, April 26, 2013 14:14:55 Walter Bright wrote: > On 4/26/2013 12:37 PM, Jonathan M Davis wrote: > > There's nothing whatsoever about bool that > > makes sense as an integral type. > > This is where our perspectives sharply diverge. A bool is a 1 bit integer > type. Take a look at this, fo

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Rob T
On Friday, 26 April 2013 at 21:37:14 UTC, Walter Bright wrote: On 4/26/2013 1:59 PM, Andrej Mitrovic wrote: On 4/26/13, Andrej Mitrovic wrote: An even better example: import std.stdio; void foo(bool x) { writeln("1"); } void foo(long x) { writeln("2"); } void main() { foo(1); // "1"

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Jonathan M Davis
On Friday, April 26, 2013 14:34:45 Walter Bright wrote: > D has an interesting feature called VRP (value range propagation), where > implicit conversion very much depends on the value. VRP is a fantastic feature, but I think that it's coming back to bite us somewhat if foo(1) calls an overload wh

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Zach the Mystic
On Friday, 26 April 2013 at 21:34:44 UTC, Walter Bright wrote: void foo(short) { ... back up my files ... } void foo(long) { ... launch nuclear missiles ... } is a bad program. The government of North Korea would probably be perfectly happy with this program, but then again, that's a

Re: 1 matches bool, 2 matches long

2013-04-26 Thread H. S. Teoh
On Fri, Apr 26, 2013 at 08:05:45PM -0400, Jonathan M Davis wrote: > On Friday, April 26, 2013 14:34:45 Walter Bright wrote: > > D has an interesting feature called VRP (value range propagation), where > > implicit conversion very much depends on the value. > > VRP is a fantastic feature, but I thi

Re: 1 matches bool, 2 matches long

2013-04-26 Thread deadalnix
On Friday, 26 April 2013 at 19:22:51 UTC, Walter Bright wrote: I remember once a language that tried to define true and false as something other than 1 and 0. It was horrible. Don't need to look far away. Most shell do that.

Re: 1 matches bool, 2 matches long

2013-04-26 Thread deadalnix
On Friday, 26 April 2013 at 21:14:54 UTC, Walter Bright wrote: On 4/26/2013 12:37 PM, Jonathan M Davis wrote: There's nothing whatsoever about bool that makes sense as an integral type. This is where our perspectives sharply diverge. A bool is a 1 bit integer type. Then why does it convert

Re: 1 matches bool, 2 matches long

2013-04-26 Thread deadalnix
On Friday, 26 April 2013 at 21:32:32 UTC, Tove wrote: On Friday, 26 April 2013 at 21:01:17 UTC, Brian Schott wrote: On Friday, 26 April 2013 at 06:01:27 UTC, Walter Bright wrote: The real issue is do you want to have the implicit conversions: 0 => false 1 => true or would you require a cast?

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Mehrdad
On Friday, 26 April 2013 at 21:37:14 UTC, Walter Bright wrote: On 4/26/2013 1:59 PM, Andrej Mitrovic wrote: On 4/26/13, Andrej Mitrovic wrote: An even better example: import std.stdio; void foo(bool x) { writeln("1"); } void foo(long x) { writeln("2"); } void main() { foo(1); // "1"

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Mehrdad
On Saturday, 27 April 2013 at 01:43:12 UTC, deadalnix wrote: On Friday, 26 April 2013 at 21:14:54 UTC, Walter Bright wrote: On 4/26/2013 12:37 PM, Jonathan M Davis wrote: There's nothing whatsoever about bool that makes sense as an integral type. This is where our perspectives sharply diverge

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Maxim Fomin
On Friday, 26 April 2013 at 21:34:44 UTC, Walter Bright wrote: On 4/26/2013 1:59 PM, Diggory wrote: The actual value shouldn't be taken into account when determining which overload to call, only the type should matter, D has an interesting feature called VRP (value range propagation), where

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Rob T
On Saturday, 27 April 2013 at 01:37:22 UTC, deadalnix wrote: On Friday, 26 April 2013 at 19:22:51 UTC, Walter Bright wrote: I remember once a language that tried to define true and false as something other than 1 and 0. It was horrible. Don't need to look far away. Most shell do that. D can

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Luís.Marques
Is this what some of you are asking for? bool a = true; // ok bool b = false;// ok bool c = 1; // error, no implicit conversion bool c = getInt();// error? ok? int x = 42; if(x) { ... } // ok (doesn't this imply c = getInt() ok to

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Steven Schveighoffer
On Thu, 25 Apr 2013 23:01:30 -0700, Walter Bright wrote: D tries very hard to avoid the notion of a "better" match. It goes with an exact match, followed by one with implicit conversions. All implicit conversions are considered equally good. Ambiguity is resolved by invoking "partial ord

Re: 1 matches bool, 2 matches long

2013-04-26 Thread Mehrdad
On Saturday, 27 April 2013 at 05:54:48 UTC, Luís Marques wrote: Is this what some of you are asking for? bool a = true; // ok Yes bool b = false;// ok Yes bool c = 1; // error, no implicit conversion Yes bool c = getInt();// error? ok? Ye

Re: 1 matches bool, 2 matches long

2013-04-27 Thread deadalnix
On Friday, 26 April 2013 at 21:37:14 UTC, Walter Bright wrote: On 4/26/2013 1:59 PM, Andrej Mitrovic wrote: On 4/26/13, Andrej Mitrovic wrote: An even better example: import std.stdio; void foo(bool x) { writeln("1"); } void foo(long x) { writeln("2"); } void main() { foo(1); // "1"

Re: 1 matches bool, 2 matches long

2013-04-27 Thread deadalnix
On Saturday, 27 April 2013 at 05:54:48 UTC, Luís Marques wrote: Is this what some of you are asking for? bool a = true; // ok bool b = false;// ok bool c = 1; // error, no implicit conversion bool c = getInt();// error? ok? Last 2 are error. in

Re: 1 matches bool, 2 matches long

2013-04-27 Thread khurshid
On Friday, 26 April 2013 at 18:22:10 UTC, Walter Bright wrote: On 4/26/2013 6:51 AM, deadalnix wrote: The last time I experienced that feature was with a char getting casted to bool implicitly and then appended to a string, causing super weird behavior after when using the resulting (corrupted

Re: 1 matches bool, 2 matches long

2013-04-27 Thread kenji hara
First, I can guess that why Walter disagree *fixing* this problem. http://dlang.org/overview.html > Major Design Goals of D > 9. Where D code looks the same as C code, have it either behave the same or issue an error. Based on the design goal, we should not change the behavior toward foo(1) match

Re: 1 matches bool, 2 matches long

2013-04-27 Thread Andrej Mitrovic
On 4/27/13, kenji hara wrote: > // The expected behavior we can do at the most > extern(C) int printf(const char*, ...); > void foo(bool) { printf("bool\n"); } > void foo(long) { printf("long\n"); } > void main() > { > foo(0); // Error: function foo called with argument types: (int) matches > b

Re: 1 matches bool, 2 matches long

2013-04-27 Thread bearophile
Andrej Mitrovic: That's even more stupid. Please be gentle. That from Kenji is one of the few usable ideas of this thread. Bye, bearophile

Re: 1 matches bool, 2 matches long

2013-04-27 Thread deadalnix
On Saturday, 27 April 2013 at 12:20:00 UTC, bearophile wrote: Andrej Mitrovic: That's even more stupid. Please be gentle. That from Kenji is one of the few usable ideas of this thread. Bye, bearophile No, that is even worse.

Re: 1 matches bool, 2 matches long

2013-04-27 Thread Minas Mina
On Saturday, 27 April 2013 at 11:41:30 UTC, kenji hara wrote: First, I can guess that why Walter disagree *fixing* this problem. http://dlang.org/overview.html Major Design Goals of D 9. Where D code looks the same as C code, have it either behave the same or issue an error. C doesn't hav

Re: 1 matches bool, 2 matches long

2013-04-27 Thread kenji hara
OK. I misunderstood. C does not allow function overloading, so same problem is not there. In C++, // test.cpp #include void foo(bool) { printf("bool\n"); } void foo(long) { printf("long\n"); } int main(int argc, char **argv) { foo(false); // matches bool version foo(true); // matches bool ver

Re: 1 matches bool, 2 matches long

2013-04-27 Thread Diggory
On Saturday, 27 April 2013 at 10:17:58 UTC, deadalnix wrote: On Friday, 26 April 2013 at 21:37:14 UTC, Walter Bright wrote: On 4/26/2013 1:59 PM, Andrej Mitrovic wrote: On 4/26/13, Andrej Mitrovic wrote: An even better example: import std.stdio; void foo(bool x) { writeln("1"); } void foo(

Re: 1 matches bool, 2 matches long

2013-04-27 Thread MattCoder
One of the main problem that I saw here, is this behavior (DMD 2.062): import std.stdio; void foo(bool b) { writeln("bool"); } void foo(long l) { writeln("long"); } void main() { int num = 0; foo(num); foo(0); foo(2); } output: long bool long As num = 0, for me both: "foo(num)" and "foo(0)"

Re: 1 matches bool, 2 matches long

2013-04-27 Thread kenji hara
I filed the issue in bugzilla, and opened pull request to fix it. http://d.puremagic.com/issues/show_bug.cgi?id= https://github.com/D-Programming-Language/dmd/pull/1942 Kenji Hara 2013/4/28 kenji hara > OK. I misunderstood. > > C does not allow function overloading, so same problem is not

Re: 1 matches bool, 2 matches long

2013-04-27 Thread Walter Bright
On 4/26/2013 7:36 PM, Mehrdad wrote: Walter, you're completely missing the point. I completely understand it is a perception problem. Some people see bool as a 1 bit integer (including me). Some see bool as something very distinct from integers (including you). An analogous issue comes up h

Re: 1 matches bool, 2 matches long

2013-04-27 Thread Walter Bright
On 4/26/2013 5:14 PM, H. S. Teoh wrote: Does VRP work only with literals, or does it work with general variables (by inferring from, say, if-conditions)? void func(int i) { ubyte b; if (i >= 0 && i < 256) { b = i; // OK wit

Re: 1 matches bool, 2 matches long

2013-04-27 Thread Walter Bright
On 4/26/2013 9:19 PM, Maxim Fomin wrote: Then perhaps ban VRP on arguments if it affects overloading? That'll just make another group of people unhappy. It's like designing a house with a fixed footprint. You can make the kitchen larger and the bathroom smaller, or vice versa, but you can't m

Re: 1 matches bool, 2 matches long

2013-04-27 Thread Walter Bright
On 4/27/2013 8:11 AM, kenji hara wrote: Walter, now I changed my opinion. It seems not correct that being regarded bool type as one of the integer. How about? Both C and C++ regard bool as an integer, and implicitly convert 1/0 to true/false. What C++ doesn't have is VRP and partial ordering

Re: 1 matches bool, 2 matches long

2013-04-27 Thread Walter Bright
On 4/26/2013 3:28 PM, Jonathan M Davis wrote: Sure, it may be useful sometimes to have code that treats true as 1 and false as 0 for math, but I'd argue for casting being required for it, and in a large number of cases, casting would be required already due to the fact that it would be a narrowin

Re: 1 matches bool, 2 matches long

2013-04-27 Thread kenji hara
2013/4/28 Walter Bright > On 4/27/2013 8:11 AM, kenji hara wrote: > >> Walter, now I changed my opinion. It seems not correct that being >> regarded bool >> type as one of the integer. >> How about? >> > > Both C and C++ regard bool as an integer, and implicitly convert 1/0 to > true/false. > > W

Re: 1 matches bool, 2 matches long

2013-04-27 Thread Walter Bright
On 4/26/2013 11:04 PM, Steven Schveighoffer wrote: I think the issue (and I am firmly in the foo(1) => long camp) is that bools are considered better integers than actual integer types (or even floating point types for that matter). I agree that bools can be implicitly cast to and from integers,

Re: 1 matches bool, 2 matches long

2013-04-27 Thread kenji hara
(This is a quotation from http://d.puremagic.com/issues/show_bug.cgi?id= ) > I do not agree with this enhancement. First off, making special cases for > partial ordering takes a simple, straightforward idea and turns it into a > potential

Re: 1 matches bool, 2 matches long

2013-04-27 Thread Mehrdad
On Saturday, 27 April 2013 at 19:51:48 UTC, Walter Bright wrote: On 4/26/2013 7:36 PM, Mehrdad wrote: Walter, you're completely missing the point. I completely understand it is a perception problem. Some people see bool as a 1 bit integer (including me). Some see bool as something very disti

Re: 1 matches bool, 2 matches long

2013-04-27 Thread Rob T
On Saturday, 27 April 2013 at 20:31:15 UTC, Mehrdad wrote: The problem is 'bool' has *NOTHING* in common with integers! - Can't use + - * / << >> on bool's Because currently D views booleans as a 1 bit int, you can do seemingly nonsensical things with the bool type bool b = false + true; //

Re: 1 matches bool, 2 matches long

2013-04-27 Thread Rob T
On Saturday, 27 April 2013 at 19:51:48 UTC, Walter Bright wrote: An analogous issue comes up here now and then about 'char' and characters. Are chars an 8 byte integer, or are they characters, or are they octets, or should access only be allowed to multibyte characters as an indivisible code po

Re: 1 matches bool, 2 matches long

2013-04-27 Thread Minas Mina
VRP is only useful when doing this: short s = 1000; // 1000 is int, but it's safe to put it into a short Integers are not booleans. I agree with the others that bool being treated as an int is an implementation detail derived from C. Or are you just bored for doing: if( x == 0 ) instead o

Re: 1 matches bool, 2 matches long

2013-04-27 Thread Walter Bright
On 4/27/2013 2:29 PM, Rob T wrote: If bools are 1 bit ints, then why do we have 'true' and 'false' as keywords? Because writing cast(bool)0 and cast(bool)1 is unappealing.

Re: 1 matches bool, 2 matches long

2013-04-27 Thread jerro
On Saturday, 27 April 2013 at 21:52:30 UTC, Walter Bright wrote: On 4/27/2013 2:29 PM, Rob T wrote: If bools are 1 bit ints, then why do we have 'true' and 'false' as keywords? Because writing cast(bool)0 and cast(bool)1 is unappealing. I would expect boolean literals to be something like 0b

Re: 1 matches bool, 2 matches long

2013-04-27 Thread eles
On Saturday, 27 April 2013 at 21:52:30 UTC, Walter Bright wrote: On 4/27/2013 2:29 PM, Rob T wrote: Because writing cast(bool)0 and cast(bool)1 is unappealing. why need to write that? just drop the bool type entirely and go ahead with an integer that you interpret as a boolean. welcome back

Re: 1 matches bool, 2 matches long

2013-04-27 Thread Mehrdad
On Saturday, 27 April 2013 at 21:52:30 UTC, Walter Bright wrote: On 4/27/2013 2:29 PM, Rob T wrote: If bools are 1 bit ints, then why do we have 'true' and 'false' as keywords? Because writing cast(bool)0 and cast(bool)1 is unappealing. Unappealing to whom?

Re: 1 matches bool, 2 matches long

2013-04-27 Thread Rob T
On Saturday, 27 April 2013 at 21:59:50 UTC, eles wrote: On Saturday, 27 April 2013 at 21:52:30 UTC, Walter Bright wrote: On 4/27/2013 2:29 PM, Rob T wrote: Because writing cast(bool)0 and cast(bool)1 is unappealing. why need to write that? just drop the bool type entirely and go ahead with an

Re: 1 matches bool, 2 matches long

2013-04-27 Thread Paulo Pinto
Am 27.04.2013 23:52, schrieb Walter Bright: On 4/27/2013 2:29 PM, Rob T wrote: If bools are 1 bit ints, then why do we have 'true' and 'false' as keywords? Because writing cast(bool)0 and cast(bool)1 is unappealing. No, this brings us back into the realm of C and weak type checking.

Re: 1 matches bool, 2 matches long

2013-04-27 Thread Namespace
If bools are 1 bit ints, then why do we have 'true' and 'false' as keywords? Those keywords only serve to confuse the programmer into thinking that the bool type is actually a real boolean type. C++ has also true and false and they are converted to integers by the compiler.

Re: 1 matches bool, 2 matches long

2013-04-27 Thread Rob T
On Saturday, 27 April 2013 at 21:52:30 UTC, Walter Bright wrote: On 4/27/2013 2:29 PM, Rob T wrote: If bools are 1 bit ints, then why do we have 'true' and 'false' as keywords? Because writing cast(bool)0 and cast(bool)1 is unappealing. That cannot be the main reason. There must be a more fu

  1   2   >