www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11213] New: Simplify switch case-range statement

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11213

           Summary: Simplify switch case-range statement
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: andrej.mitrovich gmail.com



16:19:04 PDT ---
The current case-range syntax is rather awkward and verbose:

-----
import std.stdio;

void main()
{
    foreach (x; 0 .. 10)
    {
        switch (x)
        {
            case 0: .. case 4:
                writeln("a");
                break;

            case 5: .. case 9:
                writeln("b");
                break;

            default:
        }
    }
}
-----

I suggest we allow the syntax "case 0 .. 4:", e.g.:

-----
switch (x)
{
    case 0 .. 4:
        writeln("a");
        break;

    case 5 .. 9:
        writeln("b");
        break;

    default:
}
-----

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 09 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11213




16:19:55 PDT ---
And in fact every time I have to use a case-range statement I forget that we
use this strange syntax, I always reach for "case 0 .. 4" but end up having a
syntax error. Allowing it would be consistent with the rest of the language.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 09 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11213


rswhite4 googlemail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rswhite4 googlemail.com



Did you read that?
http://dlang.org/faq.html#case_range

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 09 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11213


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID



 http://dlang.org/faq.html#case_range
As written in the FAQ, it's intended syntax. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 09 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11213


monarchdodra gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra gmail.com




 http://dlang.org/faq.html#case_range
As written in the FAQ, it's intended syntax.
As an enhancement, I don't see why case 0 : .. case 4 : couldn't also be: case 0 .. 5; If anything, "case 0 .. 5" is more consistent with what the language does *everywhere*else*, and "case 0 : .. case 4 :" is the actual artifact that never should have existed. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 10 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11213


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc





 As an enhancement, I don't see why
 
 case 0 : .. case 4 :
 
 couldn't also be:
 
 case 0 .. 5;
 
 If anything, "case 0 .. 5" is more consistent with what the language does
 *everywhere*else*, and "case 0 : .. case 4 :" is the actual artifact that never
 should have existed.
This introduces the problem that we'll need to solve adding "[]" to iota: iota!"[]"(ubyte.min, ubyte.max) So Kenji is right. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 10 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11213


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|INVALID                     |WONTFIX



06:23:15 PDT ---
I don't buy that argument. A switch statement is special enough that inclusive
semantics for the right-hand side would not be confusing.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 10 2013