Stupid little iota of an idea

Nick Sabalausky a at a.a
Tue Feb 8 19:08:03 PST 2011


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.





More information about the Digitalmars-d mailing list