digitalmars.D - builtin sort
- Stephan Schiffels (25/25) Jun 08 2013 Hi,
- Jonathan M Davis (8/45) Jun 08 2013 Hmm, it works just fine on my system (64-bit Linux), so I don't know why...
- monarch_dodra (27/35) Jun 08 2013 Or anything that uses non-POD comparison (opCmp) for that matter:
- Stephan Schiffels (3/41) Jun 08 2013 Wow, that's much worse than in my example... indeed very
- Stephan Schiffels (5/15) Jun 08 2013 Hmm, that's bizarre, but I guess there's no need to understand
- Peter Williams (4/49) Jun 08 2013 Rather than deprecate it why not fix it? Shouldn't have to import
- bearophile (9/11) Jun 08 2013 Generally you want to keep the compiler (all its layers) as
- Stephan Schiffels (11/23) Jun 10 2013 I agree. Do people have the same opinion on the builtin reverse?
- Jacob Carlborg (8/17) Jun 10 2013 Perhaps start with modifying the compiler to indicate the "sort" and
- bearophile (8/11) Jun 10 2013 Nope. "retro" is a lazy range that yields in reverse direction.
- Stephan Schiffels (9/31) Jun 10 2013 That's not correct, it's called "reverse" and is a builtin
- Andrei Alexandrescu (6/12) Jun 10 2013 std.algorithm.reverse reverses a range in place:
- Jacob Carlborg (4/8) Jun 10 2013 Right, my bad.
- bearophile (4/4) Jun 10 2013 I have opened this issue:
- David Nadlinger (3/4) Jun 08 2013 Why not?
- Peter Williams (6/9) Jun 08 2013 Because it's large with a lot of stuff unrelated to sorting.
- David Nadlinger (3/9) Jun 08 2013 import std.algorithm : sort;
- Idan Arye (2/8) Jun 08 2013 http://forum.dlang.org/thread/kooe7p$255m$1@digitalmars.com
- nazriel (3/28) Jun 10 2013 Maybe it is related to
Hi, I know it has been discussed previously to deprecate the builtin sort. I don't know the status of this, but I observed the following problem. With dmd, druntime and phobos all on 2.063, this program runs successfully on a mac: import std.stdio; void main() { int[] a = [5, 4, 3, 2, 1]; a.sort; writeln(a); } But it fails on linux, with the line: /nfs/users/nfs_s/ss27/Software/dlang/phobos/generated/linux/release/64/libphobos2 a(qsort_4c4_2cc.o): In function `_adSort': src/rt/qsort.d:(.text._adSort+0x47): undefined reference to `qsort_r' collect2: ld returned 1 exit status --- errorlevel 1 When I change "a.sort" -> "a.sort()" and add import std.algorithm everything works fine. Does this mean that the builtin sort on Linux is broken with 2.063? Stephan
Jun 08 2013
On Saturday, June 08, 2013 10:30:52 Stephan Schiffels wrote:Hi, I know it has been discussed previously to deprecate the builtin sort. I don't know the status of this, but I observed the following problem. With dmd, druntime and phobos all on 2.063, this program runs successfully on a mac: import std.stdio; void main() { int[] a = [5, 4, 3, 2, 1]; a.sort; writeln(a); } But it fails on linux, with the line: /nfs/users/nfs_s/ss27/Software/dlang/phobos/generated/linux/release/64/libph obos2.a(qsort_4c4_2cc.o): In function `_adSort': src/rt/qsort.d:(.text._adSort+0x47): undefined reference to `qsort_r' collect2: ld returned 1 exit status --- errorlevel 1 When I change "a.sort" -> "a.sort()" and add import std.algorithm everything works fine. Does this mean that the builtin sort on Linux is broken with 2.063?Hmm, it works just fine on my system (64-bit Linux), so I don't know why you're seeing the problem that you're seeing. However, we really, really need to deprecate the built-in sort - especially when a pair of parens can make the difference between whether you call the built-in sort or std.algorithm's sort - and it's particularly broken with regards to Unicode. - Jonathan M Davis
Jun 08 2013
On Saturday, 8 June 2013 at 08:52:22 UTC, Jonathan M Davis wrote:However, we really, really need to deprecate the built-in sort - especially when a pair of parens can make the difference between whether you call the built-in sort or std.algorithm's sort - and it's particularly broken with regards to Unicode. - Jonathan M DavisOr anything that uses non-POD comparison (opCmp) for that matter: //---- import std.stdio; import std.algorithm; struct S { int i; int opCmp(S o) { return (i < o.i) - (i > o.i); //inverse order } } void main() { auto a = [S(1), S(2), S(3)]; writeln(a); //[S(1), S(2), S(3)] a.sort; writeln(a); //[S(1), S(2), S(3)] a.sort(); writeln(a); //[S(3), S(2), S(1)] } //---- I had pretty much forgotten ".sort" even existed (it really never even crossed my mind that it could be built-in), and given the push for optional parenthesis in general (especially in UFCS call chains), I can say I am surprised by this behavior.
Jun 08 2013
On Saturday, 8 June 2013 at 09:16:23 UTC, monarch_dodra wrote:On Saturday, 8 June 2013 at 08:52:22 UTC, Jonathan M Davis wrote:Wow, that's much worse than in my example... indeed very unexpected behaviour.However, we really, really need to deprecate the built-in sort - especially when a pair of parens can make the difference between whether you call the built-in sort or std.algorithm's sort - and it's particularly broken with regards to Unicode. - Jonathan M DavisOr anything that uses non-POD comparison (opCmp) for that matter: //---- import std.stdio; import std.algorithm; struct S { int i; int opCmp(S o) { return (i < o.i) - (i > o.i); //inverse order } } void main() { auto a = [S(1), S(2), S(3)]; writeln(a); //[S(1), S(2), S(3)] a.sort; writeln(a); //[S(1), S(2), S(3)] a.sort(); writeln(a); //[S(3), S(2), S(1)] } //---- I had pretty much forgotten ".sort" even existed (it really never even crossed my mind that it could be built-in), and given the push for optional parenthesis in general (especially in UFCS call chains), I can say I am surprised by this behavior.
Jun 08 2013
On Saturday, 8 June 2013 at 08:52:22 UTC, Jonathan M Davis wrote:Hmm, it works just fine on my system (64-bit Linux), so I don't know why you're seeing the problem that you're seeing.Hmm, that's bizarre, but I guess there's no need to understand this further since things work fine with std.algorithm.sort.However, we really, really need to deprecate the built-in sort - especially when a pair of parens can make the difference between whether you call the built-in sort or std.algorithm's sort - and it's particularly broken with regards to Unicode.Yes, I completely agree! Stephan
Jun 08 2013
On 08/06/13 18:51, Jonathan M Davis wrote:On Saturday, June 08, 2013 10:30:52 Stephan Schiffels wrote:Rather than deprecate it why not fix it? Shouldn't have to import std.algorithm just to sort an array. PeterHi, I know it has been discussed previously to deprecate the builtin sort. I don't know the status of this, but I observed the following problem. With dmd, druntime and phobos all on 2.063, this program runs successfully on a mac: import std.stdio; void main() { int[] a = [5, 4, 3, 2, 1]; a.sort; writeln(a); } But it fails on linux, with the line: /nfs/users/nfs_s/ss27/Software/dlang/phobos/generated/linux/release/64/libph obos2.a(qsort_4c4_2cc.o): In function `_adSort': src/rt/qsort.d:(.text._adSort+0x47): undefined reference to `qsort_r' collect2: ld returned 1 exit status --- errorlevel 1 When I change "a.sort" -> "a.sort()" and add import std.algorithm everything works fine. Does this mean that the builtin sort on Linux is broken with 2.063?Hmm, it works just fine on my system (64-bit Linux), so I don't know why you're seeing the problem that you're seeing. However, we really, really need to deprecate the built-in sort - especially when a pair of parens can make the difference between whether you call the built-in sort or std.algorithm's sort - and it's particularly broken with regards to Unicode. - Jonathan M Davis
Jun 08 2013
Peter Williams:Rather than deprecate it why not fix it? Shouldn't have to import std.algorithm just to sort an array.Generally you want to keep the compiler (all its layers) as simpler as possible, to make it simpler to compile, debug and develop. A sort is implementable very well in library code. Other things, like tuples with a good syntax maybe can't be implemented well in library code, so they should be in the compiler :) I suggest to kill the built-in sort ASAP. Bye, bearophile
Jun 08 2013
On Saturday, 8 June 2013 at 22:51:06 UTC, bearophile wrote:Peter Williams:I agree. Do people have the same opinion on the builtin reverse? I don't remember whether there was a discussion about this. I suggest to kill that as well. sort and reverse are perfectly well implemented in the standard library rather than builtin. Is anyone actually on this? I could try to dig into it, I guess I could start looking for spurious places in phobos and druntime where these builtin functions are used and replace them with the library ones. If we deprecate it in the end we don't want to see it being used anywhere in the standard implementations. StephanRather than deprecate it why not fix it? Shouldn't have to import std.algorithm just to sort an array.Generally you want to keep the compiler (all its layers) as simpler as possible, to make it simpler to compile, debug and develop. A sort is implementable very well in library code. Other things, like tuples with a good syntax maybe can't be implemented well in library code, so they should be in the compiler :) I suggest to kill the built-in sort ASAP. Bye, bearophile
Jun 10 2013
On 2013-06-10 11:03, Stephan Schiffels wrote:I agree. Do people have the same opinion on the builtin reverse? I don't remember whether there was a discussion about this. I suggest to kill that as well. sort and reverse are perfectly well implemented in the standard library rather than builtin."reverse" is implemented with the stupid name "retro".Is anyone actually on this? I could try to dig into it, I guess I could start looking for spurious places in phobos and druntime where these builtin functions are used and replace them with the library ones. If we deprecate it in the end we don't want to see it being used anywhere in the standard implementations.Perhaps start with modifying the compiler to indicate the "sort" and "reverse" functions are deprecated. Then it will be easier to find in Phobos and druntime. Also, if used in druntime they need to be reimplemented there. -- /Jacob Carlborg
Jun 10 2013
Jacob Carlborg:"reverse" is implemented with the stupid name "retro".Nope. "retro" is a lazy range that yields in reverse direction. The Phobos in-place reverse for arrays is named "reverse". But unlike the built-in reverse returns void.Perhaps start with modifying the compiler to indicate the "sort" and "reverse" functions are deprecated.The first step for Issue 10318 is indeed a warning for usage of the built-in sort. Bye, bearophile
Jun 10 2013
On Monday, 10 June 2013 at 11:10:06 UTC, Jacob Carlborg wrote:On 2013-06-10 11:03, Stephan Schiffels wrote:That's not correct, it's called "reverse" and is a builtin property of dynamic arrays, see bearophiles answer... "retro" is lazy!I agree. Do people have the same opinion on the builtin reverse? I don't remember whether there was a discussion about this. I suggest to kill that as well. sort and reverse are perfectly well implemented in the standard library rather than builtin."reverse" is implemented with the stupid name "retro".Right, I thought so, too. Indeed, bearophiles issue addresses this in this order. I will try this on a local branch first and possibly open a pull request to start a more concrete discussion on this... StephanIs anyone actually on this? I could try to dig into it, I guess I could start looking for spurious places in phobos and druntime where these builtin functions are used and replace them with the library ones. If we deprecate it in the end we don't want to see it being used anywhere in the standard implementations.Perhaps start with modifying the compiler to indicate the "sort" and "reverse" functions are deprecated. Then it will be easier to find in Phobos and druntime. Also, if used in druntime they need to be reimplemented there.
Jun 10 2013
On 6/10/13 7:10 AM, Jacob Carlborg wrote:On 2013-06-10 11:03, Stephan Schiffels wrote:std.algorithm.reverse reverses a range in place: http://dlang.org/phobos/std_algorithm.html#reverse std.range.retro iterates a range in retrograde order without modifying AndreiI agree. Do people have the same opinion on the builtin reverse? I don't remember whether there was a discussion about this. I suggest to kill that as well. sort and reverse are perfectly well implemented in the standard library rather than builtin."reverse" is implemented with the stupid name "retro".
Jun 10 2013
On 2013-06-10 17:15, Andrei Alexandrescu wrote:std.algorithm.reverse reverses a range in place: http://dlang.org/phobos/std_algorithm.html#reverse std.range.retro iterates a range in retrograde order without modifyingRight, my bad. -- /Jacob Carlborg
Jun 10 2013
I have opened this issue: http://d.puremagic.com/issues/show_bug.cgi?id=10318 Bye, bearophile
Jun 10 2013
On Saturday, 8 June 2013 at 22:25:14 UTC, Peter Williams wrote:Shouldn't have to import std.algorithm just to sort an array.Why not? David
Jun 08 2013
On 09/06/13 08:54, David Nadlinger wrote:On Saturday, 8 June 2013 at 22:25:14 UTC, Peter Williams wrote:Because it's large with a lot of stuff unrelated to sorting. Peter PS A few weeks ago I would have said "large and ugly" but now I have a better feel for component programming it's not so ugly :-) but it's still large.Shouldn't have to import std.algorithm just to sort an array.Why not?
Jun 08 2013
On Sunday, 9 June 2013 at 00:03:04 UTC, Peter Williams wrote:On 09/06/13 08:54, David Nadlinger wrote:import std.algorithm : sort; DavidOn Saturday, 8 June 2013 at 22:25:14 UTC, Peter Williams wrote:Because it's large with a lot of stuff unrelated to sorting.Shouldn't have to import std.algorithm just to sort an array.Why not?
Jun 08 2013
On Sunday, 9 June 2013 at 00:03:04 UTC, Peter Williams wrote:On 09/06/13 08:54, David Nadlinger wrote:http://forum.dlang.org/thread/kooe7p$255m$1 digitalmars.comOn Saturday, 8 June 2013 at 22:25:14 UTC, Peter Williams wrote:Because it's large with a lot of stuff unrelated to sorting.Shouldn't have to import std.algorithm just to sort an array.Why not?
Jun 08 2013
On Saturday, 8 June 2013 at 08:30:54 UTC, Stephan Schiffels wrote:Hi, I know it has been discussed previously to deprecate the builtin sort. I don't know the status of this, but I observed the following problem. With dmd, druntime and phobos all on 2.063, this program runs successfully on a mac: import std.stdio; void main() { int[] a = [5, 4, 3, 2, 1]; a.sort; writeln(a); } But it fails on linux, with the line: /nfs/users/nfs_s/ss27/Software/dlang/phobos/generated/linux/release/64/libphobos2 a(qsort_4c4_2cc.o): In function `_adSort': src/rt/qsort.d:(.text._adSort+0x47): undefined reference to `qsort_r' collect2: ld returned 1 exit status --- errorlevel 1 When I change "a.sort" -> "a.sort()" and add import std.algorithm everything works fine. Does this mean that the builtin sort on Linux is broken with 2.063? StephanMaybe it is related to https://github.com/D-Programming-Language/druntime/pull/427
Jun 10 2013