Re: foreach and retro

2012-07-04 Thread Joseph Rushton Wakeling
On 02/07/12 18:57, kenji hara wrote: D does not provide index for the range iteration. Instead, you can create 'zipped' range. Oh, cool. That's a nice feature that I can think of other uses for ... :-)

Re: foreach and retro

2012-07-04 Thread Joseph Rushton Wakeling
On 02/07/12 18:43, bearophile wrote: It's not a bug, it's caused by how ranges like retro work. retro yields a single item. In D you can't overload on return values, so foreach can't try to call a second retro.front overload that yields an (index,item) tuple (that later foreach is able to unpack

Re: foreach and retro

2012-07-02 Thread Christophe Travert
"bearophile" , dans le message (digitalmars.D:171013), a écrit : > It's not a bug, it's caused by how ranges like retro work. retro > yields a single item. In D you can't overload on return values, But you can overload OpApply. -- Christophe

Re: foreach and retro

2012-07-02 Thread kenji hara
D does not provide index for the range iteration. Instead, you can create 'zipped' range. void main() { auto intr = sequence!"n"(); // 0, 1, 2, ... double[] a = [ 0, 1, 2, 3, 4, 5 ]; foreach(i, x; zip(intr, retro(a))) writeln(i, "\t", x); } zip(intr, retro(a)) is a

Re: foreach and retro

2012-07-02 Thread Namespace
On Monday, 2 July 2012 at 16:49:06 UTC, Joseph Rushton Wakeling wrote: On 02/07/12 17:48, Timon Gehr wrote: What would be your expected output? I'd expect to see 0 5 1 4 2 3 3 2 4 1 5 0 i.e. as if I was foreach-ing over an array with the same values in inverted order

Re: foreach and retro

2012-07-02 Thread Joseph Rushton Wakeling
On 02/07/12 17:48, Timon Gehr wrote: What would be your expected output? I'd expect to see 0 5 1 4 2 3 3 2 4 1 5 0 i.e. as if I was foreach-ing over an array with the same values in inverted order.

Re: foreach and retro

2012-07-02 Thread bearophile
Joseph Rushton Wakeling: double[] a = [ 0, 1, 2, 3, 4, 5 ]; foreach(i, x; retro(a)) writeln(i, "\t", x); It's not a bug, it's caused by how ranges like retro work. retro yields a single item. In D you can't overload on return values, so foreach can't try to call a se

Re: foreach and retro

2012-07-02 Thread Tobias Pankrath
What would be your expected output? From the inner to the outer expression: First the range is reversed and then the elements of this range are enumerated.

Re: foreach and retro

2012-07-02 Thread Timon Gehr
On 07/02/2012 05:36 PM, Joseph Rushton Wakeling wrote: Hello all, A problem with the retro function from std.range -- although it apparently operates on a bidirectional range, it fails when used with foreach requesting both value and index. Running this code: //

Re: foreach and retro

2012-07-02 Thread Joseph Rushton Wakeling
Running this code Sorry, should be "attempting to compile this code".

foreach and retro

2012-07-02 Thread Joseph Rushton Wakeling
Hello all, A problem with the retro function from std.range -- although it apparently operates on a bidirectional range, it fails when used with foreach requesting both value and index. Running this code: import std.range, std.stdio; void mai