foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed for floats
Denis Koroskin
2korden at gmail.com
Mon May 18 03:18:07 PDT 2009
On Mon, 18 May 2009 04:28:24 +0400, Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org> wrote:
> Consider:
>
> foreach (x; 1.0 .. 4.1) writeln(x);
> foreach_reverse (x; 1.0 .. 4.1) writeln(x);
>
> This sucks. foreach with interval for floating-point types should be
> disallowed.
>
>
> Andrei
It's useless, unless a step is specified (btw, integer iteration would benefit from having a step, too)
I don't mind if the whole .. feature is removed. It could be implemented in a library, with an optional step:
foreach (x; range(0, 100)) { // step is 1 implicitly
// ...
}
foreach (x; range(0, 100, 2)) { // explicit step
// ...
}
This feels more functional, although slightly longer to type.
More information about the Digitalmars-d
mailing list