On 02/09/2011 04:08 AM, Nick Sabalausky wrote:
AUIU, foreach has both of these forms:

     foreach(x; 0..5)
     foreach(x; someRange)

Also, we have:

     auto someRange = iota(0, 5);

Little idea: How about this genralized lowering?

     0..5
     // iota says "Gimme some sugar, baby."
     // and thus it is lowered to ->
     iota(0, 5)

Of course, if that hinders optimization for foreach(x; 0..5), then the
compiler could just "optimize" that particular case by not bothering with
the lowering and doing as it currently does.

But the benefit is things like this:

     // Stealing Andrei's "filter even" example:
     filter!`a % 2 == 0`(iota(1, 5))
     // Give iota some sugar, baby:
     filter!`a % 2 == 0`(1..5)

I suppose the obnoxious float-literal definition could get in the way, but
when is it ever legal syntax in D to have two numeric literals next to each
other? (And foreach seems ok with it anyway)

Pardon if this has already been suggested.

I like this. Maybe a slightly different approach would be for both 1..5 and iota(1,5) to be expressions for a simple and range-semantic-compatible struct-like thingy. Then, actually, iota would be superfluous, but some may still like it syntactically or semantically (because Iota is explicitely defined as a range type). Side-question: what is actually 1..5 as of now for a thing? Or is it conceptually "unconstructed" by rewriting to (probably) an ordinary for loop? Anyway, the point above applies to language-side semantics, whatever optimisation may happen.

Denis
--
_________________
vita es estrany
spir.wikidot.com

Reply via email to