[Issue 5395] Interval literals
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Feb 9 04:55:05 PST 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5395
Denis Derman <denis.spir at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |denis.spir at gmail.com
--- Comment #1 from Denis Derman <denis.spir at gmail.com> 2011-02-09 04:52:39 PST ---
(In reply to comment #0)
> 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
Rather doubtful on this; actually topic of your other enhancement request
http://d.puremagic.com/issues/show_bug.cgi?id=4112; see comment there.
> 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) {...}
Yo, just suggested this and the above (both syntaxes are equivalent) on the
mailing list.
> 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)) {...}
The important point is that, whatever representation and/or rewriting happens
on the implementation side, on the language side i..j provide range-compatible
semantics (like arrays). It needs not /be/ an instance of Iota (which may also
be rewritten, indeed).
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