Re: std.algorithm sort() and reverse() confusion

2015-02-02 Thread bearophile via Digitalmars-d-learn
Jonathan M Davis: arr.reverse.map!sqrt Yes, but arguably, chaining calls in this case is bad, We have discussed this some time... and I'd like reverse() to return the original array (like the deprecated array .reverse property). It's not a perfect design, but allowing UFCS chains is qu

Re: std.algorithm sort() and reverse() confusion

2015-01-30 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, January 30, 2015 10:46:54 Ali Çehreli via Digitalmars-d-learn wrote: > On 01/30/2015 09:55 AM, Jonathan M Davis via Digitalmars-d-learn wrote: > > there is no such benefit with reverse, so there's no need to > > return anything. > > Still, returning the original range would help with c

Re: std.algorithm sort() and reverse() confusion

2015-01-30 Thread Paul via Digitalmars-d-learn
On Friday, 30 January 2015 at 18:46:55 UTC, Ali Çehreli wrote: > there is no such benefit with reverse, so there's no need to > return anything. Still, returning the original range would help with chaining calls: arr.reverse.map!sqrt Side note: There is the confusion between the .reverse p

Re: std.algorithm sort() and reverse() confusion

2015-01-30 Thread Ali Çehreli via Digitalmars-d-learn
On 01/30/2015 09:55 AM, Jonathan M Davis via Digitalmars-d-learn wrote: > sort returns a different type rather than the original type, and that type > indicates that its sorted, and some algoritms are able to take advantage of > that. I covered that a little bit during DConf 2014, at around 4

Re: std.algorithm sort() and reverse() confusion

2015-01-30 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, January 30, 2015 18:42:57 FG via Digitalmars-d-learn wrote: > On 2015-01-30 at 17:07, Paul wrote: > > writeln("Sorted, reversed: ", reverse(myVals)); > > > > Gives me... > > > > Error: template std.stdio.writeln cannot deduce function from argument > > types !()(string, void) > > As it

Re: std.algorithm sort() and reverse() confusion

2015-01-30 Thread FG via Digitalmars-d-learn
On 2015-01-30 at 18:42, FG wrote: But you may wonder what the design choice behind that was that reverse doesn't return the range itself while sort does (a SortedRange, specifically). Although, after thinking about it, it makes sense. sort is used mostly to enforce that something is sorted in

Re: std.algorithm sort() and reverse() confusion

2015-01-30 Thread FG via Digitalmars-d-learn
On 2015-01-30 at 17:07, Paul wrote: writeln("Sorted, reversed: ", reverse(myVals)); Gives me... Error: template std.stdio.writeln cannot deduce function from argument types !()(string, void) As it should, because reverse returns nothing, void. But you may wonder what the design choice behind

Re: std.algorithm sort() and reverse() confusion

2015-01-30 Thread Tobias Pankrath via Digitalmars-d-learn
On Friday, 30 January 2015 at 17:07:17 UTC, Paul wrote: On Friday, 30 January 2015 at 16:21:24 UTC, Kagamin wrote: writeln("Sorted, reversed: ", retro(sort(myVals))); ? Or... writeln("Reverse sorted: ", sort!("a > b")(vals)); but I still don't understand the original 'error'. Take a look a

Re: std.algorithm sort() and reverse() confusion

2015-01-30 Thread Paul via Digitalmars-d-learn
On Friday, 30 January 2015 at 16:21:24 UTC, Kagamin wrote: writeln("Sorted, reversed: ", retro(sort(myVals))); ? Or... writeln("Reverse sorted: ", sort!("a > b")(vals)); but I still don't understand the original 'error'.

Re: std.algorithm sort() and reverse() confusion

2015-01-30 Thread Kagamin via Digitalmars-d-learn
writeln("Sorted, reversed: ", retro(sort(myVals))); ?

std.algorithm sort() and reverse() confusion

2015-01-30 Thread Paul via Digitalmars-d-learn
Given that myVals is a dynamic array of ints... writeln("Array contents: ", myVals); writeln("Sorted: ", sort(myVals)); writeln("Sorted, reversed: ", reverse(myVals)); Gives me... Error: template std.stdio.writeln cannot deduce function from argument types !()(string, void) But, if I bring t