View mode: basic / threaded / horizontal-split · Log in · Help
June 09, 2013
Re: builtin sort
On Sunday, 9 June 2013 at 00:03:04 UTC, Peter Williams wrote:
> On 09/06/13 08:54, David Nadlinger wrote:
>> 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?
>
> Because it's large with a lot of stuff unrelated to sorting.

http://forum.dlang.org/thread/kooe7p$255m$1@digitalmars.com
June 10, 2013
Re: builtin sort
On Saturday, 8 June 2013 at 22:51:06 UTC, bearophile wrote:
> 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

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.

Stephan
June 10, 2013
Re: builtin sort
I have opened this issue:

http://d.puremagic.com/issues/show_bug.cgi?id=10318

Bye,
bearophile
June 10, 2013
Re: builtin sort
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
June 10, 2013
Re: builtin sort
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
June 10, 2013
Re: builtin sort
On Monday, 10 June 2013 at 11:10:06 UTC, Jacob Carlborg wrote:
> 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".

That's not correct, it's called "reverse" and is a builtin 
property of dynamic arrays, see bearophiles answer... "retro" is 
lazy!

>
>> 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.

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...

Stephan
June 10, 2013
Re: builtin sort
On 6/10/13 7:10 AM, Jacob Carlborg wrote:
> 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".

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 
it: http://dlang.org/phobos/std_range.html#.retro


Andrei
June 10, 2013
Re: builtin sort
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:
>
> #!/usr/bin/env rdmd
>
> 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

Maybe it is related to 
https://github.com/D-Programming-Language/druntime/pull/427
June 10, 2013
Re: builtin sort
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 modifying
> it: http://dlang.org/phobos/std_range.html#.retro

Right, my bad.

-- 
/Jacob Carlborg
Next ›   Last »
1 2
Top | Discussion index | About this forum | D home