digitalmars.D.learn - foreach_reverse error
- ixid (8/8) May 09 2012 With this code foreach works but foreach_reverse does not:
- Timon Gehr (2/10) May 09 2012 group returns a lazy forward range. use foreach(i; group(retro(ints)))
- ixid (2/2) May 09 2012 Thanks, sorry to have not understand such a basic point, it's
- Timon Gehr (2/4) May 09 2012 No worries.
- H. S. Teoh (5/18) May 09 2012 Yet another reason foreach_reverse needs to go.
- bearophile (5/6) May 09 2012 Nope, the specific kind of range of group not being what the OP
- mta`chrono (1/8) May 11 2012 No please don't! There are hundred and ten very usefull cases.
- Steven Schveighoffer (11/19) May 11 2012 No, there is only one.
With this code foreach works but foreach_reverse does not: void main() { int[] ints = [2,2,2,5,5,5,4,4,4]; auto temp = group(ints); foreach_reverse(i;temp) i[1].writeln; } Is this a known issue? Is there a sensible reason for this?
May 09 2012
On 05/09/2012 10:50 PM, ixid wrote:With this code foreach works but foreach_reverse does not: void main() { int[] ints = [2,2,2,5,5,5,4,4,4]; auto temp = group(ints); foreach_reverse(i;temp) i[1].writeln; } Is this a known issue? Is there a sensible reason for this?group returns a lazy forward range. use foreach(i; group(retro(ints)))
May 09 2012
Thanks, sorry to have not understand such a basic point, it's rather hard to get to grips with everything like this in D.
May 09 2012
On 05/09/2012 11:33 PM, ixid wrote:Thanks, sorry to have not understand such a basic point, it's rather hard to get to grips with everything like this in D.No worries.
May 09 2012
On Wed, May 09, 2012 at 11:09:15PM +0200, Timon Gehr wrote:On 05/09/2012 10:50 PM, ixid wrote:Yet another reason foreach_reverse needs to go. T -- It only takes one twig to burn down a forest.With this code foreach works but foreach_reverse does not: void main() { int[] ints = [2,2,2,5,5,5,4,4,4]; auto temp = group(ints); foreach_reverse(i;temp) i[1].writeln; } Is this a known issue? Is there a sensible reason for this?group returns a lazy forward range. use foreach(i; group(retro(ints)))
May 09 2012
H. S. Teoh:Yet another reason foreach_reverse needs to go.Nope, the specific kind of range of group not being what the OP desired is not foreach_reverse fault. Bye, bearophile
May 09 2012
No please don't! There are hundred and ten very usefull cases.group returns a lazy forward range. use foreach(i; group(retro(ints)))Yet another reason foreach_reverse needs to go. T
May 11 2012
On Fri, 11 May 2012 03:43:53 -0400, mta`chrono <chrono mta-international.net> wrote:No, there is only one. foreach_reverse(i; 0..10) {...} Every other usage of foreach_reverse can be rewritten with foreach. I would argue that this should work: foreach(i; 10..0) but it would be quite odd given that you would start with 9 and end with 0. I don't have a really good answer for this, foreach(i; 9..-1) isn't really acceptable, especially if i is unsigned. -SteveNo please don't! There are hundred and ten very usefull cases.group returns a lazy forward range. use foreach(i; group(retro(ints)))Yet another reason foreach_reverse needs to go. T
May 11 2012