http://d.puremagic.com/issues/show_bug.cgi?id=5395

           Summary: Interval literals
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: bearophile_h...@eml.cc


--- Comment #0 from bearophile_h...@eml.cc 2011-01-01 06:32:05 PST ---
Sometimes it's positive to replace some language feature with good Phobos
implementations (like complex numbers), but language design is an iterative
process, so sometimes it's positive to go the other way too. Tuples and number
intervals are two examples where I think it will be good to add some syntax
sugar back into the front-end. This enhancement request is about the number
intervals.

I suggest for the two following syntaxes to be seen by the compiler as
equivalent, as syntax sugar of each other:
foreach (i; 0 .. 10)
foreach (i; iota(0, 10))

So I suggest the x..y syntax to become first class and to mean
std.range.iota(x,y).

An extension of the interval literal may allow a step value too:

0 .. 10:2

Once present the interval literal becomes useful to remove a () from lazy
expressions, making them more readable:
reduce!max(map!foo(1 .. 1000))
Instead of:
reduce!max(map!foo(iota(1, 1000)))

If the interval literal becomes first class, it's possible to use it for ranged
types, or interval tests too:
if (x in 5 .. 20) {...}

If iota becomes syntax sugar for the ranged sequence, then the compiler is able
to compile better simple code like this:
foreach (i; iota(0, 10, 2)) {...}

See also bug 4603

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

Reply via email to