January 29, 2016 reduce -> fold? | ||||
---|---|---|---|---|
| ||||
As has been discussed before there's been discussion about std.algorithm.reduce taking the "wrong" order of arguments (its definition predates UFCS). I recall the conclusion was there'd be subtle ambiguities if we worked reduce to implement both orders. So the next best solution is to introduce a new name such as the popular "fold", and put them together in the documentation. Thoughts? Andrei |
January 29, 2016 Re: reduce -> fold? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Friday, 29 January 2016 at 12:08:01 UTC, Andrei Alexandrescu wrote: > As has been discussed before there's been discussion about std.algorithm.reduce taking the "wrong" order of arguments (its definition predates UFCS). I recall the conclusion was there'd be subtle ambiguities if we worked reduce to implement both orders. > > So the next best solution is to introduce a new name such as the popular "fold", and put them together in the documentation. > > > Thoughts? YES! There was a topic on this [1] and some implementation proposed. I'm not sure if it was the only one. [1] http://forum.dlang.org/post/sqbizjwcyavbrxwagnwl@forum.dlang.org |
January 29, 2016 Re: reduce -> fold? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Friday, 29 January 2016 at 12:08:01 UTC, Andrei Alexandrescu wrote:
> So the next best solution is to introduce a new name such as the popular "fold", and put them together in the documentation.
Just to bikeshed a little, I remember that when I first started using std.algorithm I was ctrl-F'ing for "accumulate" and not finding it quite often. D competes with C++ directly, so do consider that name :-)
|
January 29, 2016 Re: reduce -> fold? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Luís Marques | On Friday, 29 January 2016 at 13:11:34 UTC, Luís Marques wrote: > Just to bikeshed a little, I remember that when I first started using std.algorithm I was ctrl-F'ing for "accumulate" and not finding it quite often. D competes with C++ directly, so do consider that name :-) But not in python, where "accumulate"[1] is the generic equivalent of C++ "partial_sum"[2]. I like "fold" more. BTW this week, a colleague of mine implemented a python "accumulate" in D. Is there any interest to contribute it to Phobos? How should this be named? [1] https://docs.python.org/3/library/itertools.html#itertools.accumulate [2] http://en.cppreference.com/w/cpp/algorithm/partial_sum |
January 29, 2016 Re: reduce -> fold? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dragos Carp | On Friday, 29 January 2016 at 13:56:48 UTC, Dragos Carp wrote:
> But not in python, where "accumulate"[1] is the generic equivalent of C++ "partial_sum"[2]. I like "fold" more.
>
> BTW this week, a colleague of mine implemented a python "accumulate" in D. Is there any interest to contribute it to Phobos? How should this be named?
>
> [1] https://docs.python.org/3/library/itertools.html#itertools.accumulate
> [2] http://en.cppreference.com/w/cpp/algorithm/partial_sum
Fair enough. Yes, that is indeed a useful algorithm, so please do contribute. I won't bikeshed on that other name, heh.
|
January 29, 2016 Re: reduce -> fold? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Friday, 29 January 2016 at 12:08:01 UTC, Andrei Alexandrescu wrote:
> As has been discussed before there's been discussion about std.algorithm.reduce taking the "wrong" order of arguments (its definition predates UFCS). I recall the conclusion was there'd be subtle ambiguities if we worked reduce to implement both orders.
>
> So the next best solution is to introduce a new name such as the popular "fold", and put them together in the documentation.
>
>
> Thoughts?
>
> Andrei
Yes yes yes please!
|
January 29, 2016 Re: reduce -> fold? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Friday, 29 January 2016 at 12:08:01 UTC, Andrei Alexandrescu wrote:
> As has been discussed before there's been discussion about std.algorithm.reduce taking the "wrong" order of arguments (its definition predates UFCS). I recall the conclusion was there'd be subtle ambiguities if we worked reduce to implement both orders.
>
> So the next best solution is to introduce a new name such as the popular "fold", and put them together in the documentation.
>
>
> Thoughts?
>
> Andrei
Absolutely yes!
|
January 29, 2016 Re: reduce -> fold? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Friday, 29 January 2016 at 12:08:01 UTC, Andrei Alexandrescu wrote:
> As has been discussed before there's been discussion about std.algorithm.reduce taking the "wrong" order of arguments (its definition predates UFCS). I recall the conclusion was there'd be subtle ambiguities if we worked reduce to implement both orders.
>
> So the next best solution is to introduce a new name such as the popular "fold", and put them together in the documentation.
>
>
> Thoughts?
>
> Andrei
I think yes. Took me ages to realise the difference with reduce.
|
January 29, 2016 Re: reduce -> fold? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Friday, 29 January 2016 at 12:08:01 UTC, Andrei Alexandrescu wrote: > As has been discussed before there's been discussion about std.algorithm.reduce taking the "wrong" order of arguments (its definition predates UFCS). I recall the conclusion was there'd be subtle ambiguities if we worked reduce to implement both orders. > > So the next best solution is to introduce a new name such as the popular "fold", and put them together in the documentation. > > > Thoughts? > > Andrei +1 Let's make sure to write the half dozen other names for it in the documentation so people coming to D from other languages can easily find it. And just for completeness, here is monarchdodra's valiant but ultimately unsuccessful pull request which attempted fix reduce: https://github.com/D-Programming-Language/phobos/pull/861#issuecomment-20760448 |
January 29, 2016 Re: reduce -> fold? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brad Anderson | On Friday, 29 January 2016 at 16:38:23 UTC, Brad Anderson wrote: > And just for completeness, here is monarchdodra's valiant but ultimately unsuccessful pull request which attempted fix reduce: https://github.com/D-Programming-Language/phobos/pull/861#issuecomment-20760448 Interestingly, that pull request links to another pull request which introduces fold, so we can just merge that one :) ? https://github.com/D-Programming-Language/phobos/pull/2033 |
Copyright © 1999-2021 by the D Language Foundation