Re: Enums - probably an old subject

2013-11-22 Thread Steve Teale
Does it make sense? I should be really in D.learn but asked that here in context ;) Sounds like most of us should be in D Learn on this topic. I should find the time to write up a case for Andrei's suggestion. I have no problem with the compiler telling me that my code is ambiguous, in fac

Re: Enums - probably an old subject

2013-11-21 Thread monarch_dodra
On Friday, 22 November 2013 at 00:50:25 UTC, John J wrote: On 11/21/2013 02:20 PM, monarch_dodra wrote: When you import from a module, you only need to specify the module name if there is ambiguity. So for example: // import std.array; void main() { split("hello"); //OK! } // im

Re: Enums - probably an old subject

2013-11-21 Thread John J
On 11/21/2013 01:36 PM, Steve Teale wrote: I thought that compilers were supposed to help you if you did ambiguous things. An interesting example is: int bar(int n) { return n+1; } int bar(int n) { return n+2; } void main() { int v = 22; int n = bar(22); } Compiler helps her

Re: Enums - probably an old subject

2013-11-21 Thread John J
On 11/21/2013 02:20 PM, monarch_dodra wrote: When you import from a module, you only need to specify the module name if there is ambiguity. So for example: // import std.array; void main() { split("hello"); //OK! } // import std.array; import std.algorithm; void main() { spl

Re: Enums - probably an old subject

2013-11-21 Thread John J
On 11/21/2013 02:20 PM, monarch_dodra wrote: When you import from a module, you only need to specify the module name if there is ambiguity. So for example: // import std.array; void main() { split("hello"); //OK! } // import std.array; import std.algorithm; void main() { spli

Re: Enums - probably an old subject

2013-11-21 Thread inout
On Thursday, 21 November 2013 at 07:22:39 UTC, Steve Teale wrote: import std.stdio; enum Intention { EVIL, NEUTRAL, GOOD, SAINTLY } void foo(Intention rth) { if (rth == EVIL) writeln("Road to hell"); } void main() { foo(EVIL); } Why does the compiler complain in both

Re: Enums - probably an old subject

2013-11-21 Thread monarch_dodra
On Thursday, 21 November 2013 at 18:44:39 UTC, Steve Teale wrote: On Thursday, 21 November 2013 at 17:39:28 UTC, Andrei Alexandrescu wrote: On 11/21/13 8:48 AM, Steve Teale wrote: Could 'with' be extended to cover enum names do you think? Also a supplementary question - does auto lock out some

Re: Enums - probably an old subject

2013-11-21 Thread Steve Teale
On Thursday, 21 November 2013 at 08:05:03 UTC, Michal Minich wrote: On Thursday, 21 November 2013 at 07:42:48 UTC, Craig Dillabaugh wrote: I should also mention, this post likely better belongs in: digitalmars.D.learn I don't entirely think so. I think the OP is arguing that D should be able

Re: Enums - probably an old subject

2013-11-21 Thread Steve Teale
That should be: if( rth == Intention.EVIL ) and foo( Intention.EVIL ); Phobos is less picky than the compiler. Try this: import std.stdio; enum Intention { EVIL, NEUTRAL, GOOD, SAINTLY } void foo(Intention rth) { if (rth == Intention.EVIL) writefln("The road to hell is

Re: Enums - probably an old subject

2013-11-21 Thread inout
On Thursday, 21 November 2013 at 17:19:18 UTC, inout wrote: On Thursday, 21 November 2013 at 07:22:39 UTC, Steve Teale wrote: import std.stdio; enum Intention { EVIL, NEUTRAL, GOOD, SAINTLY } void foo(Intention rth) { if (rth == EVIL) writeln("Road to hell"); } void main() {

Re: Enums - probably an old subject

2013-11-21 Thread Steve Teale
BOOM! Code no longer compiles. As a rule, the code that compiles and works should preserve its behavior when new code is added, so this is prohibited. Also please post to D.learn forgot to add: void foo(OtherIntention rth) { ... } Which of the two is being called by main? I thought that

Re: Enums - probably an old subject

2013-11-21 Thread Steve Teale
On Thursday, 21 November 2013 at 17:39:28 UTC, Andrei Alexandrescu wrote: On 11/21/13 8:48 AM, Steve Teale wrote: Could 'with' be extended to cover enum names do you think? Also a supplementary question - does auto lock out some things like this, are there other examples? Guess it could. One

Re: Enums - probably an old subject

2013-11-21 Thread Brad Anderson
On Thursday, 21 November 2013 at 17:39:28 UTC, Andrei Alexandrescu wrote: On 11/21/13 8:48 AM, Steve Teale wrote: Could 'with' be extended to cover enum names do you think? Also a supplementary question - does auto lock out some things like this, are there other examples? Guess it could. One

Re: Enums - probably an old subject

2013-11-21 Thread Meta
On Thursday, 21 November 2013 at 16:48:59 UTC, Steve Teale wrote: Could 'with' be extended to cover enum names do you think? Also a supplementary question - does auto lock out some things like this, are there other examples? Is this what you mean? enum Intention { EVIL, NEUTRA

Re: Enums - probably an old subject

2013-11-21 Thread Andrei Alexandrescu
On 11/21/13 8:48 AM, Steve Teale wrote: Could 'with' be extended to cover enum names do you think? Also a supplementary question - does auto lock out some things like this, are there other examples? Guess it could. One other thing we could do is to make enum namespaces behave like imports. A

Re: Enums - probably an old subject

2013-11-21 Thread Steve Teale
On Thursday, 21 November 2013 at 08:37:32 UTC, Craig Dillabaugh wrote: Yes, perhaps that was his intention (no pun intended). First few times I used enums in D I was caught because I expected the behavior he is suggesting here would work. Pun was intended ;=)

Re: Enums - probably an old subject

2013-11-21 Thread Craig Dillabaugh
On Thursday, 21 November 2013 at 08:05:03 UTC, Michal Minich wrote: On Thursday, 21 November 2013 at 07:42:48 UTC, Craig Dillabaugh wrote: I should also mention, this post likely better belongs in: digitalmars.D.learn I don't entirely think so. I think the OP is arguing that D should be able

Re: Enums - probably an old subject

2013-11-21 Thread Michal Minich
On Thursday, 21 November 2013 at 07:42:48 UTC, Craig Dillabaugh wrote: I should also mention, this post likely better belongs in: digitalmars.D.learn I don't entirely think so. I think the OP is arguing that D should be able to identify symbol as specific enum's field when used: - in place

Re: Enums - probably an old subject

2013-11-21 Thread Daniel Kozak
On Thursday, 21 November 2013 at 07:22:39 UTC, Steve Teale wrote: import std.stdio; enum Intention { EVIL, NEUTRAL, GOOD, SAINTLY } void foo(Intention rth) { if (rth == EVIL) writeln("Road to hell"); } void main() { foo(EVIL); } Why does the compiler complain in both

Re: Enums - probably an old subject

2013-11-20 Thread Craig Dillabaugh
On Thursday, 21 November 2013 at 07:28:14 UTC, Craig Dillabaugh wrote: On Thursday, 21 November 2013 at 07:22:39 UTC, Steve Teale wrote: clip Why does the compiler complain in both places about EVIL. Can it not work out which EVIL I mean? There's only one choice. That should be: if( rth =

Re: Enums - probably an old subject

2013-11-20 Thread Craig Dillabaugh
On Thursday, 21 November 2013 at 07:22:39 UTC, Steve Teale wrote: import std.stdio; enum Intention { EVIL, NEUTRAL, GOOD, SAINTLY } void foo(Intention rth) { if (rth == EVIL) writeln("Road to hell"); } void main() { foo(EVIL); } Why does the compiler complain in both

Enums - probably an old subject

2013-11-20 Thread Steve Teale
import std.stdio; enum Intention { EVIL, NEUTRAL, GOOD, SAINTLY } void foo(Intention rth) { if (rth == EVIL) writeln("Road to hell"); } void main() { foo(EVIL); } Why does the compiler complain in both places about EVIL. Can it not work out which EVIL I mean? There's