Re: foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed for floats

2009-05-18 Thread Leandro Lucarella
bearophile, el 18 de mayo a las 11:19 me escribiste: > Leandro Lucarella: > > > > foreach(i, elem; retro(someArray)) {} > > > > Python has an "enumerate" function exactly for this. > > Not exactly for that. To have something like that you need something more > (reversed is lazy): > > >>> itera

Re: foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed for floats

2009-05-18 Thread Steven Schveighoffer
On Mon, 18 May 2009 13:30:19 -0400, Bill Baxter wrote: On Mon, May 18, 2009 at 9:21 AM, Steven Schveighoffer wrote: On Mon, 18 May 2009 12:02:30 -0400, Andrei Alexandrescu I'm a bit leery about this - what if user code has a bug and I transform that into a feature? hm... I guess that's o

Re: foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed for floats

2009-05-18 Thread Bill Baxter
On Mon, May 18, 2009 at 9:21 AM, Steven Schveighoffer wrote: > On Mon, 18 May 2009 12:02:30 -0400, Andrei Alexandrescu >> I'm a bit leery about this - what if user code has a bug and I transform >> that into a feature? > > hm... I guess that's one way to look at it.  I don't anticipate many typing

Re: foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed for floats

2009-05-18 Thread Steven Schveighoffer
On Mon, 18 May 2009 12:02:30 -0400, Andrei Alexandrescu wrote: Steven Schveighoffer wrote: On Sun, 17 May 2009 20:28:24 -0400, Andrei Alexandrescu wrote: Consider: foreach (x; 1.0 .. 4.1) writeln(x); foreach_reverse (x; 1.0 .. 4.1) writeln(x); This sucks. foreach with interv

Re: foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed for floats

2009-05-18 Thread Andrei Alexandrescu
Steven Schveighoffer wrote: On Mon, 18 May 2009 09:54:16 -0400, Jacob Carlborg wrote: Steven Schveighoffer wrote: On Sun, 17 May 2009 20:28:24 -0400, Andrei Alexandrescu wrote: Consider: foreach (x; 1.0 .. 4.1) writeln(x); foreach_reverse (x; 1.0 .. 4.1) writeln(x); This sucks

Re: foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed for floats

2009-05-18 Thread Andrei Alexandrescu
dsimcha wrote: 2. Using retro() would not be a full replacement when it comes to arrays. For example, you can't get the indices by doing a foreach(i, elem; retro(someArray)) {} This needs fixing. 4. Iteration using the range interface is currently slower than with arrays. I posted some b

Re: foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed for floats

2009-05-18 Thread Andrei Alexandrescu
Steven Schveighoffer wrote: On Sun, 17 May 2009 20:28:24 -0400, Andrei Alexandrescu 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. foreach_reverse

Re: foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed for floats

2009-05-18 Thread Andrei Alexandrescu
Denis Koroskin wrote: On Mon, 18 May 2009 04:28:24 +0400, Andrei Alexandrescu 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

Re: foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed for floats

2009-05-18 Thread bearophile
Leandro Lucarella: > > foreach(i, elem; retro(someArray)) {} > > Python has an "enumerate" function exactly for this. Not exactly for that. To have something like that you need something more (reversed is lazy): >>> iterable = "abcd" >>> for i, elem in enumerate(reversed(iterable)): ... pr

Re: foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed for floats

2009-05-18 Thread Steven Schveighoffer
On Mon, 18 May 2009 10:58:46 -0400, dsimcha wrote: I think what you're looking for is retro() in std.range. There are a few problemswith getting rid of foreach_reverse, though: 1. It would have to stay in D1. This is not a serious problem, since D2 already introduces so many breaking cha

Re: foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed for floats

2009-05-18 Thread Leandro Lucarella
dsimcha, el 18 de mayo a las 14:58 me escribiste: > 2. Using retro() would not be a full replacement when it comes to arrays. > For > example, you can't get the indices by doing a > > foreach(i, elem; retro(someArray)) {} Python has an "enumerate" function exactly for this. Is a generator that

Re: foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed for floats

2009-05-18 Thread dsimcha
== Quote from Steven Schveighoffer (schvei...@yahoo.com)'s article > On Mon, 18 May 2009 09:54:16 -0400, Jacob Carlborg wrote: > > Steven Schveighoffer wrote: > >> On Sun, 17 May 2009 20:28:24 -0400, Andrei Alexandrescu > >> wrote: > >> > >>> Consider: > >>> > >>> foreach (x; 1.0 .. 4.1) wri

Re: foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed for floats

2009-05-18 Thread Steven Schveighoffer
On Mon, 18 May 2009 09:54:16 -0400, Jacob Carlborg wrote: Steven Schveighoffer wrote: On Sun, 17 May 2009 20:28:24 -0400, Andrei Alexandrescu 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

Re: foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed for floats

2009-05-18 Thread Jacob Carlborg
Steven Schveighoffer wrote: On Sun, 17 May 2009 20:28:24 -0400, Andrei Alexandrescu 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. foreach_reverse

Re: foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed for floats

2009-05-18 Thread Steven Schveighoffer
On Sun, 17 May 2009 20:28:24 -0400, Andrei Alexandrescu 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. foreach_reverse sucks in its own right, whi

Re: foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed for floats

2009-05-18 Thread Denis Koroskin
On Mon, 18 May 2009 04:28:24 +0400, Andrei Alexandrescu 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 spe

Re: foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed for floats

2009-05-18 Thread Lars T. Kyllingstad
Andrei Alexandrescu 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 I didn't even know this was possible, but I agree, it's an ugly thing. -Lar

Re: foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed for floats

2009-05-17 Thread Andrei Alexandrescu
Georg Wrede wrote: Andrei Alexandrescu 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. As long as you don't also remove the regular for loop with float

Re: foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed for floats

2009-05-17 Thread Georg Wrede
Andrei Alexandrescu 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. As long as you don't also remove the regular for loop with floating-point types.

Re: foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed for floats

2009-05-17 Thread dsimcha
== Quote from Andrei Alexandrescu (seewebsiteforem...@erdani.org)'s article > 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 This one I agree with.

foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed for floats

2009-05-17 Thread Andrei Alexandrescu
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