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.

PS: your proposal would also logically allow, I guess, expressions like (n in min..max). Would love it.

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

Reply via email to