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

2009-05-18 Thread Bill Baxter
On Mon, May 18, 2009 at 5:46 AM, Jason House wrote: > Here's a recent misuse by Andrei that made its way into Phobos: > if (is(T == struct) && is(T.toString)) Hmm, 'is' isn't supposed to accept values is it? But it quietly ignores anything wrong and returns false. Is that the misuse you're tal

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

2009-05-18 Thread bearophile
Steven Schveighoffer: > hm... I guess that's one way to look at it. I don't anticipate many > typing this by mistake. One thing that would be left to decide, 1..4 > means 1-2-3, should 4..1 mean 4-3-2 or 3-2-1? I'd vote for 4-3-2 to be > consistent on having x..y mean inclusive to exclusi

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

2009-05-18 Thread bearophile
Jason House: >how do you test for an associative array of string types indexes by a >numerical type while exposing a type alias for the index type?< When I use my dlibs in D1 to solve a problem like that I use: static if (IsAA!(T1) && IsNumeric!(KeyType!(T1))) { alias KeyType!(T1) Tkey;

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

2009-05-18 Thread Jason House
grauzone Wrote: > Robert Fraser wrote: > > Jason House 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 shou

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

2009-05-18 Thread grauzone
Christopher Wright wrote: grauzone wrote: Look at this for example: > writefln("%s", is(typeof(rtzx) == char)); This compiles even if rtzx doesn't exist. But you probably wanted to check the type of rtzx, not it if rtzx exists. If you mistyped rtzx, the compiler will never tell you. You can

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

2009-05-18 Thread Christopher Wright
grauzone wrote: Look at this for example: > writefln("%s", is(typeof(rtzx) == char)); This compiles even if rtzx doesn't exist. But you probably wanted to check the type of rtzx, not it if rtzx exists. If you mistyped rtzx, the compiler will never tell you. You can do 'is(typeof(rtzx)) && is

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

2009-05-17 Thread grauzone
Robert Fraser wrote: Jason House 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. Andrei I agree that makes little sense

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

2009-05-17 Thread Jesse Phillips
On Sun, 17 May 2009 21:25:50 -0400, Jason House wrote: > > I agree that makes little sense. > > I'm curious, why the sudden pruning of features? Can you please consider > removing SFINAE? I'd also love to see is expressions go the way of the > dinosaur. I don't know what their replacement should

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

2009-05-17 Thread Andrei Alexandrescu
Robert Fraser wrote: Jason House 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. Andrei I agree that makes little sense

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

2009-05-17 Thread Robert Fraser
Jason House 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. Andrei I agree that makes little sense. I'm curious, why th

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

2009-05-17 Thread Andrei Alexandrescu
Jason House 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. Andrei I agree that makes little sense. I'm curious, why the sudden pru

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

2009-05-17 Thread Jason House
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 agree that makes little sense. I'm curious, why the su

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