| Thread overview | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
March 31, 2016 foreach_reverse and lockstep. | ||||
|---|---|---|---|---|
| ||||
Why doesn't reverse iteration of lockstep work? It does for zip. Is this intended or is it a bug? | ||||
March 31, 2016 Re: foreach_reverse and lockstep. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Sean Campbell | 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 | |||
March 31, 2016 Re: foreach_reverse and lockstep. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Sean Campbell | 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
| |||
April 01, 2016 Re: foreach_reverse and lockstep. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Sean Campbell | 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
| |||
April 01, 2016 Re: foreach_reverse and lockstep. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | 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
| |||
April 01, 2016 Re: foreach_reverse and lockstep. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Simen Kjaeraas | 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.
| |||
April 01, 2016 Re: foreach_reverse and lockstep. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to ZombineDev | 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 | |||
April 01, 2016 Re: foreach_reverse and lockstep. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to ZombineDev | 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 | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply