Re: Wrong enum comparisons

2017-01-14 Thread Era Scarecrow via Digitalmars-d
On Monday, 28 May 2012 at 13:47:47 UTC, Andrei Alexandrescu wrote: On 5/28/12 8:19 AM, foobar wrote: See functional languages such as ML for a correct implementation and also Java 5 Enums (similar but with an OO flavor). I've always found it amusing to watch what a kitchen sink Java

Re: Wrong enum comparisons

2017-01-14 Thread LemonBoy via Digitalmars-d
On Monday, 28 May 2012 at 21:01:43 UTC, bearophile wrote: Andrei Alexandrescu: I do agree that it's wrong to _conflate_ the enumerated value with it ordinal, I agree it is possible to fix enum. Thank you for your answers Andrei. I have filed an enhancement request:

Re: Wrong enum comparisons

2012-05-28 Thread Jonathan M Davis
On Sunday, May 27, 2012 21:45:22 bearophile wrote: In some code I have created a small bug that can be reduced to something like this, that the D compiler has not caught at compile-time: enum E1 { A, B } enum E2 { C, D } void main() { E1[2] a; with (E2) assert(a[0]

Re: Wrong enum comparisons

2012-05-28 Thread Denis Shelomovskij
27.05.2012 23:45, bearophile написал: In some code I have created a small bug that can be reduced to something like this, that the D compiler has not caught at compile-time: enum E1 { A, B } enum E2 { C, D } void main() { E1[2] a; with (E2) assert(a[0] == D); } Why isn't D able to statically

Re: Wrong enum comparisons

2012-05-28 Thread Dmitry Olshansky
On 28.05.2012 12:58, Denis Shelomovskij wrote: 27.05.2012 23:45, bearophile написал: In some code I have created a small bug that can be reduced to something like this, that the D compiler has not caught at compile-time: enum E1 { A, B } enum E2 { C, D } void main() { E1[2] a; with (E2)

Re: Wrong enum comparisons

2012-05-28 Thread bearophile
Denis Shelomovskij: Enumerations are in very poor state in D now. ... By the way, current enums can be modified to correspond list enumeration and flags can be added as library component. I think D enums need to become a bit more strict (so you can't equal elements of different enums).

Re: Wrong enum comparisons

2012-05-28 Thread Araq
Pascal got type safe enums and sets of enums (aka flags) right in the 60ies. Too bad not even Ada copied this nice feature. Fortunately, Nimrod does.

Re: Wrong enum comparisons

2012-05-28 Thread foobar
On Monday, 28 May 2012 at 08:58:29 UTC, Denis Shelomovskij wrote: 27.05.2012 23:45, bearophile написал: In some code I have created a small bug that can be reduced to something like this, that the D compiler has not caught at compile-time: enum E1 { A, B } enum E2 { C, D } void main() {

Re: Wrong enum comparisons

2012-05-28 Thread Andrei Alexandrescu
On 5/28/12 8:19 AM, foobar wrote: I have to loudly object to this definition. Given a typical enumeration such as: enum color {Blue, Green, Red}; Who's to say that Blue must equal 0? This is conceptually plain *wrong*. A conceptually correct enumeration must NOT expose such implementation

Re: Wrong enum comparisons

2012-05-28 Thread bearophile
Andrei Alexandrescu: I do agree that it's wrong to _conflate_ the enumerated value with it ordinal, so in this program neither comparison should compile without an explicit cast: enum E1 { A, B } enum E2 { C, D } void main() { E1 a; assert(a == 0); assert(a == E2.C); } The

Re: Wrong enum comparisons

2012-05-28 Thread foobar
On Monday, 28 May 2012 at 13:47:47 UTC, Andrei Alexandrescu wrote: On 5/28/12 8:19 AM, foobar wrote: I have to loudly object to this definition. Given a typical enumeration such as: enum color {Blue, Green, Red}; Who's to say that Blue must equal 0? This is conceptually plain *wrong*. A

Re: Wrong enum comparisons

2012-05-28 Thread Marco Leise
Am Mon, 28 May 2012 13:48:23 +0200 schrieb Araq rump...@web.de: Pascal got type safe enums and sets of enums (aka flags) right in the 60ies. Too bad not even Ada copied this nice feature. Fortunately, Nimrod does. Yes, I really like Pascal for that feature. Actually it is a mix of features

Re: Wrong enum comparisons

2012-05-28 Thread Andrei Alexandrescu
On 5/28/12 1:07 PM, foobar wrote: It depends on what exactly the general concept is, is this a predefined set of values or is it an ordered list. I'd argue that the set is more general and we shouldn't force an ordering when one isn't strictly required. Of course, the programmer should be able

Re: Wrong enum comparisons

2012-05-28 Thread Jonathan M Davis
On Monday, May 28, 2012 14:21:14 Andrei Alexandrescu wrote: On 5/28/12 1:07 PM, foobar wrote: It depends on what exactly the general concept is, is this a predefined set of values or is it an ordered list. I'd argue that the set is more general and we shouldn't force an ordering when one

Re: Wrong enum comparisons

2012-05-28 Thread Andrei Alexandrescu
On 5/28/12 2:37 PM, Jonathan M Davis wrote: enum does need some work, but I think that the fact that it can be both built- in types such as int as well as user-defined structs is great. It essentially gives us the best of both worlds (basic enums such as in C/C++ and more complex types as in

Re: Wrong enum comparisons

2012-05-28 Thread bearophile
Andrei Alexandrescu: I do agree that it's wrong to _conflate_ the enumerated value with it ordinal, I agree it is possible to fix enum. Thank you for your answers Andrei. I have filed an enhancement request: http://d.puremagic.com/issues/show_bug.cgi?id=8157 Issue 8157 is a subset of

Wrong enum comparisons

2012-05-27 Thread bearophile
In some code I have created a small bug that can be reduced to something like this, that the D compiler has not caught at compile-time: enum E1 { A, B } enum E2 { C, D } void main() { E1[2] a; with (E2) assert(a[0] == D); } Why isn't D able to statically tell when you

Re: Wrong enum comparisons

2012-05-27 Thread Mehrdad
On Monday, 28 May 2012 at 05:33:28 UTC, Mehrdad wrote: The *real* question is, why don't you need the E2 qualifier when you say D? well never mind, I need sleep... I didn't see you were using 'with'.

Re: Wrong enum comparisons

2012-05-27 Thread Mehrdad
The *real* question is, why don't you need the E2 qualifier when you say D?