www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - foreach_reverse and lockstep.

reply Sean Campbell <sycam.inc gmail.com> writes:
Why doesn't reverse iteration of lockstep work? It does for zip. 
Is this intended or is it a bug?
Mar 30 2016
next sibling parent ZombineDev <petar.p.kirov gmail.com> writes:
On Thursday, 31 March 2016 at 03:12:34 UTC, Sean Campbell wrote:
 Why doesn't reverse iteration of lockstep work? It does for 
 zip. Is this intended or is it a bug?
Lockstep is actually not a range. It overloads the opApply[1] operator to support foreach. To support foreach_reverse, it would also have to override opApplyReverse. I'd say that it's not a bug but still a valid enhancement request. BTW the upcomming release has better documentation on the differences between lockstep [2] and zip [3]. [1]: https://github.com/D-Programming-Language/phobos/blob/master/std/range/package.d#L4153 [2]: http://dlang.org/phobos-prerelease/std_range#lockstep [3]: http://dlang.org/phobos-prerelease/std_range#zip
Mar 31 2016
prev sibling next sibling parent Jack Stouffer <jack jackstouffer.com> writes:
On Thursday, 31 March 2016 at 03:12:34 UTC, Sean Campbell wrote:
 Why doesn't reverse iteration of lockstep work? It does for 
 zip. Is this intended or is it a bug?
Please file an enhancement request at issues.dlang.org
Mar 31 2016
prev sibling parent reply Jonathan M Davis via Digitalmars-d <digitalmars-d puremagic.com> writes:
On Thursday, March 31, 2016 03:12:34 Sean Campbell via Digitalmars-d wrote:
 Why doesn't reverse iteration of lockstep work? It does for zip.
 Is this intended or is it a bug?
Glancing over the code quickly, it looks like lockstep doesn't actually generate a range but an object that defines opApply so that it can be used in a foreach loop but not in general range-based algorithms. IIRC, it used to be that opApply worked with foreach_reverse but did exactly the same thing as foreach, so it was made an error to use it with foreach_reverse rather than having the buggy behavior persist and confuse folks (you'd need some sort of opApplyReverse function to go with foreach_reverse, and no such thing exists). zip, on the other hand, generates an actual range, and if the ranges that it's given are bidirectional ranges, then it too will be a bidirectional range, and it'll work with foreach_reverse via the back and popBack functions. - Jonathan M Davis
Apr 01 2016
parent reply Simen Kjaeraas <simen.kjaras gmail.com> writes:
On Friday, 1 April 2016 at 14:37:36 UTC, Jonathan M Davis wrote:
 (you'd need some sort of opApplyReverse function to go with 
 foreach_reverse, and no such thing exists).
Actually, it exists and it works. It's just not implemented for lockstep. I'm trying to clean up my Phobos repo so I can make a PR to fix this. Apparently I need to learn more git. :) -- Simen
Apr 01 2016
parent reply ZombineDev <petar.p.kirov gmail.com> writes:
On Friday, 1 April 2016 at 16:10:01 UTC, Simen Kjaeraas wrote:
 On Friday, 1 April 2016 at 14:37:36 UTC, Jonathan M Davis wrote:
 (you'd need some sort of opApplyReverse function to go with 
 foreach_reverse, and no such thing exists).
Actually, it exists and it works. It's just not implemented for lockstep. I'm trying to clean up my Phobos repo so I can make a PR to fix this. Apparently I need to learn more git. :) -- Simen
I'm already working on a PR. I think I can be ready by tomorrow.
Apr 01 2016
next sibling parent ZombineDev <petar.p.kirov gmail.com> writes:
On Friday, 1 April 2016 at 17:44:40 UTC, ZombineDev wrote:
 On Friday, 1 April 2016 at 16:10:01 UTC, Simen Kjaeraas wrote:
 On Friday, 1 April 2016 at 14:37:36 UTC, Jonathan M Davis 
 wrote:
 (you'd need some sort of opApplyReverse function to go with 
 foreach_reverse, and no such thing exists).
Actually, it exists and it works. It's just not implemented for lockstep. I'm trying to clean up my Phobos repo so I can make a PR to fix this. Apparently I need to learn more git. :) -- Simen
I'm already working on a PR. I think I can be ready by tomorrow.
https://issues.dlang.org/show_bug.cgi?id=15860
Apr 01 2016
prev sibling parent Simen Kjaeraas <simen.kjaras gmail.com> writes:
On Friday, 1 April 2016 at 17:44:40 UTC, ZombineDev wrote:
 On Friday, 1 April 2016 at 16:10:01 UTC, Simen Kjaeraas wrote:
 On Friday, 1 April 2016 at 14:37:36 UTC, Jonathan M Davis 
 wrote:
 (you'd need some sort of opApplyReverse function to go with 
 foreach_reverse, and no such thing exists).
Actually, it exists and it works. It's just not implemented for lockstep. I'm trying to clean up my Phobos repo so I can make a PR to fix this. Apparently I need to learn more git. :) -- Simen
I'm already working on a PR. I think I can be ready by tomorrow.
Sure, but mine's ready now :p https://github.com/D-Programming-Language/phobos/pull/4138 -- Simen
Apr 01 2016