digitalmars.D - Should reduce take range as first argument?
- Justin Whear (17/17) May 14 2012 In its current form, std.algorithm.reduce takes optional seed value(s)
- Andrei Alexandrescu (9/26) May 14 2012 Yah, reduce was not designed for the future benefit of UFCS. (I recall
- Mehrdad (2/7) May 14 2012 Just need to be careful with the constraints...
- Timon Gehr (11/41) May 14 2012 Just as for take, the new order is backwards. I don't know what to do
- monarch_dodra (13/22) Oct 04 2012 [Resurrecting old thread]
- monarch_dodra (6/8) Oct 11 2012 Well, I went and implemented the option of doing it Range first,
- bearophile (6/8) Oct 11 2012 To reduce deprecation troubles there is a Bugzilla suggestion to
- monarch_dodra (16/24) Oct 11 2012 Hum...
- monarch_dodra (4/31) Nov 29 2012 Anyone?
- Andrei Alexandrescu (3/5) Nov 29 2012 I think it's a good idea, will look at the diff.
In its current form, std.algorithm.reduce takes optional seed value(s) for the accumulator(s) as its first argument(s). This breaks the nice chaining effect made possible by UFCS: Works: ----------------------------------------- auto foo = reduce!((string s, string x) => s ~= x)("BLAH", args.map!(x => x[1..$-1])); ----------------------------------------- Doesn't work, but looks much nicer: ----------------------------------------- auto foo = args.map!(x => x[1..$-1])) .reduce!((string s, string x) => s ~= x)("BLAH"); ----------------------------------------- This could be fixed with a breaking change by making the subject range to be the first parameter. Aside from breaking existing code, are there other obstacles to changing this? Justin Whear
May 14 2012
On 5/14/12 4:10 PM, Justin Whear wrote:In its current form, std.algorithm.reduce takes optional seed value(s) for the accumulator(s) as its first argument(s). This breaks the nice chaining effect made possible by UFCS: Works: ----------------------------------------- auto foo = reduce!((string s, string x) => s ~= x)("BLAH", args.map!(x => x[1..$-1])); ----------------------------------------- Doesn't work, but looks much nicer: ----------------------------------------- auto foo = args.map!(x => x[1..$-1])) .reduce!((string s, string x) => s ~= x)("BLAH"); ----------------------------------------- This could be fixed with a breaking change by making the subject range to be the first parameter. Aside from breaking existing code, are there other obstacles to changing this? Justin WhearYah, reduce was not designed for the future benefit of UFCS. (I recall take() was redefined towards that vision, and it was a good move.) We can actually deprecate the current order and accept both by inserting the appropriate template constraints. We change the documentation and examples to reflect the new order, and we leave a note saying that the old order is deprecated. We can leave the deprecated version in place for a long time. Thoughts? Andrei
May 14 2012
On Monday, 14 May 2012 at 21:33:19 UTC, Andrei Alexandrescu wrote:We can actually deprecate the current order and accept both by inserting the appropriate template constraints. We change the documentation and examples to reflect the new order, and we leave a note saying that the old order is deprecated. We can leave the deprecated version in place for a long time. Thoughts?Just need to be careful with the constraints...
May 14 2012
On 05/14/2012 11:33 PM, Andrei Alexandrescu wrote:On 5/14/12 4:10 PM, Justin Whear wrote:Just as for take, the new order is backwards. I don't know what to do about it though. Also, what would be the deprecation path for reduction of a range of this form: class Foo{ Foo front(); bool empty(); void popFront(); } :o)In its current form, std.algorithm.reduce takes optional seed value(s) for the accumulator(s) as its first argument(s). This breaks the nice chaining effect made possible by UFCS: Works: ----------------------------------------- auto foo = reduce!((string s, string x) => s ~= x)("BLAH", args.map!(x => x[1..$-1])); ----------------------------------------- Doesn't work, but looks much nicer: ----------------------------------------- auto foo = args.map!(x => x[1..$-1])) .reduce!((string s, string x) => s ~= x)("BLAH"); ----------------------------------------- This could be fixed with a breaking change by making the subject range to be the first parameter. Aside from breaking existing code, are there other obstacles to changing this? Justin WhearYah, reduce was not designed for the future benefit of UFCS. (I recall take() was redefined towards that vision, and it was a good move.) We can actually deprecate the current order and accept both by inserting the appropriate template constraints. We change the documentation and examples to reflect the new order, and we leave a note saying that the old order is deprecated. We can leave the deprecated version in place for a long time. Thoughts? Andrei
May 14 2012
On Monday, 14 May 2012 at 21:33:19 UTC, Andrei Alexandrescu wrote:Yah, reduce was not designed for the future benefit of UFCS. (I recall take() was redefined towards that vision, and it was a good move.) We can actually deprecate the current order and accept both by inserting the appropriate template constraints. We change the documentation and examples to reflect the new order, and we leave a note saying that the old order is deprecated. We can leave the deprecated version in place for a long time. Thoughts? Andrei[Resurrecting old thread] I've into somebody else having this issue in .Learn very recently. I was *going* to propose this change myself, but happened on this thread directly. I think it is a good idea. Looks like nobody tackled this since. Is it OK if I go ahead and implement this? Just ot be clear, the goal is to support both: reduce(range, seed) and reduce(seed, range) Then we make reduce(seed, range) deprecated Then we remove it. I'd rather have a green light here, then force the discussion on a pull request... :D
Oct 04 2012
On Thursday, 4 October 2012 at 07:25:20 UTC, monarch_dodra wrote:I'd rather have a green light here, then force the discussion on a pull request... :DWell, I went and implemented the option of doing it Range first, then Seed, so that UFCS works. https://github.com/D-Programming-Language/phobos/pull/861 Whether or not we deprecate the old syntax, I guess, is still up to debate.
Oct 11 2012
monarch_dodra:Well, I went and implemented the option of doing it Range first, then Seed, so that UFCS works.To reduce deprecation troubles there is a Bugzilla suggestion to call it fold(): http://d.puremagic.com/issues/show_bug.cgi?id=8755 Bye, bearophile
Oct 11 2012
On Thursday, 11 October 2012 at 11:17:51 UTC, bearophile wrote:monarch_dodra:Hum... I can go either way. Both have their ups and downs. *fold: **No ambiguity during a migration **No ambiguity regarding argument ordering **Duplicates function names **Changes a (relatively) established function name. **Higher code impact if we deprecate reduce *reduce **Will create some ambiguity, as both reduce(r,s) and reduce(s, r) will be valid. **Will only impact reduce with seed if we deprecate the old ordering. I wouldn't mind getting a nudge in the right direction if anybody has a stance on this (Andrei?)Well, I went and implemented the option of doing it Range first, then Seed, so that UFCS works.To reduce deprecation troubles there is a Bugzilla suggestion to call it fold(): http://d.puremagic.com/issues/show_bug.cgi?id=8755 Bye, bearophile
Oct 11 2012
On Thursday, 11 October 2012 at 12:34:17 UTC, monarch_dodra wrote:On Thursday, 11 October 2012 at 11:17:51 UTC, bearophile wrote:Anyone? The pull has been open for a bit more than a month now, with no feedback...monarch_dodra:Hum... I can go either way. Both have their ups and downs. *fold: **No ambiguity during a migration **No ambiguity regarding argument ordering **Duplicates function names **Changes a (relatively) established function name. **Higher code impact if we deprecate reduce *reduce **Will create some ambiguity, as both reduce(r,s) and reduce(s, r) will be valid. **Will only impact reduce with seed if we deprecate the old ordering. I wouldn't mind getting a nudge in the right direction if anybody has a stance on this (Andrei?)Well, I went and implemented the option of doing it Range first, then Seed, so that UFCS works.To reduce deprecation troubles there is a Bugzilla suggestion to call it fold(): http://d.puremagic.com/issues/show_bug.cgi?id=8755 Bye, bearophile
Nov 29 2012
On 11/29/12 11:02 AM, monarch_dodra wrote:Anyone? The pull has been open for a bit more than a month now, with no feedback...I think it's a good idea, will look at the diff. Andrei
Nov 29 2012