[Issue 5395] Interval literals

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Feb 12 23:38:24 PST 2011


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



--- Comment #6 from Denis Derman <denis.spir at gmail.com> 2011-02-12 23:35:51 PST ---
(In reply to comment #3)
> Michel Fortin:
> 
> > how do you rewrite this using the new proposed syntax:
> >
> >         auto aa = [iota(a, b, c): 1, iota(d, e): 2];

I like the proposal by Andrej Mitrovic on the mailing list:

But maybe we could extend the array slice syntax to construct [iota] ranges:

filter!`a % 2 == 0`([1..5])
auto r = [0 .. 5];

So if the slice sits on its own it becomes a range. Or is this too
scary/ambiguous?

I don't really like them alone:
filter!`a % 2 == 0`(1..5)
auto r = 0 .. 5;

My comment:

This means basically, for slicing:
   (array expression)~(interval notation) ==> slice operation
This also allows noting a step without any syntax problem:
    [start..end:step]
Finally, as noted by someone, this allows reinterpreting slicing as a special
case of indexing, possibly unifying metamethods opIndex & opSlice, and opening
the door to easier custom rules like multi-dimensional semantics.

The issue is indeed this syntax conflicts with current:
    foreach (n ; i..j)
Too bad we have not had this form from the start...

Denis

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


More information about the Digitalmars-d-bugs mailing list