Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-08 Thread Timon Gehr via Digitalmars-d-learn
On 08.06.2017 14:06, Steven Schveighoffer wrote: The issue here is that arrays are special. Arrays allow foreach(i, v; arr) and foreach(v; arr). Ranges in general do not. So there is no way to forward this capability via the range interface. Not only that, but foreach(i, v; arr) is much

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/7/17 9:57 PM, Andrew Edwards wrote: Ranges may be finite or infinite but, while the destination may be unreachable, we can definitely tell how far we've traveled. So why doesn't this work? import std.traits; import std.range; void main() { string[string] aa; // what others have

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-08 Thread Russel Winder via Digitalmars-d-learn
On Thu, 2017-06-08 at 00:23 -0700, Jonathan M Davis via Digitalmars-d- learn wrote: > […] > > release is a member of SortedRange. You don't have to import it > separately. > You have it automatically by virtue of the fact that sort returns a > SortedRange. And unlike calling array, it doesn't

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-08 Thread Andrew Edwards via Digitalmars-d-learn
On Thursday, 8 June 2017 at 07:23:27 UTC, Jonathan M Davis wrote: release is a member of SortedRange. You don't have to import it separately. You have it automatically by virtue of the fact that sort returns a SortedRange. And unlike calling array, it doesn't copy the entire range or

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-08 Thread Russel Winder via Digitalmars-d-learn
On Wed, 2017-06-07 at 19:39 -0700, Jonathan M Davis via Digitalmars-d- learn wrote: > […] > Even better. I hadn't realized that such a function had been added. > Another import from Python. :-) -- Russel. = Dr Russel

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-08 Thread 9il via Digitalmars-d-learn
On Thursday, 8 June 2017 at 01:57:47 UTC, Andrew Edwards wrote: Ranges may be finite or infinite but, while the destination may be unreachable, we can definitely tell how far we've traveled. So why doesn't this work? import std.traits; import std.range; void main() { string[string] aa;

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-08 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, June 08, 2017 04:07:22 Andrew Edwards via Digitalmars-d-learn wrote: > On Thursday, 8 June 2017 at 03:40:08 UTC, Jonathan M Davis wrote: > > On Thursday, June 08, 2017 03:15:11 Andrew Edwards via > > > > Digitalmars-d-learn wrote: > >> I completely understand the differences between

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Andrew Edwards via Digitalmars-d-learn
On Thursday, 8 June 2017 at 04:15:12 UTC, Stanislav Blinov wrote: Earns you nothing? How about not performing an allocation and copy? Seen through the eyes of a complete beginner, this means absolutely nothing. Those are the eyes I am using as I'm reading a book and simply following the

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 8 June 2017 at 04:07:22 UTC, Andrew Edwards wrote: On Thursday, 8 June 2017 at 03:40:08 UTC, Jonathan M Davis sort() returns a SortedRange so that other algorithms can know... Yes, I understand that. Again, using "std.range: release" earns me nothing more than I already get

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Andrew Edwards via Digitalmars-d-learn
On Thursday, 8 June 2017 at 03:40:08 UTC, Jonathan M Davis wrote: On Thursday, June 08, 2017 03:15:11 Andrew Edwards via Digitalmars-d-learn wrote: I completely understand the differences between ranges and arrays... the thing is, I wasn't working with ranges but arrays instead. If sort

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, June 08, 2017 03:15:11 Andrew Edwards via Digitalmars-d-learn wrote: > On Thursday, 8 June 2017 at 02:31:43 UTC, Stanislav Blinov wrote: > > On Thursday, 8 June 2017 at 02:25:17 UTC, Jonathan M Davis > > wrote: > > > > Oh I see, the was error related to iteration, not sorting. > > >

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Era Scarecrow via Digitalmars-d-learn
On Thursday, 8 June 2017 at 02:19:15 UTC, Andrew Edwards wrote: Pretty funny. But seriously, this is something that should just work. There is now to layers of indirection to achieve what I used to do quite naturally in the language. Hmmm while working on my recent sudoku solver using

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Andrew Edwards via Digitalmars-d-learn
On Thursday, 8 June 2017 at 02:31:43 UTC, Stanislav Blinov wrote: On Thursday, 8 June 2017 at 02:25:17 UTC, Jonathan M Davis wrote: Oh I see, the was error related to iteration, not sorting. Ranges do not support iterating with an index. The workaround if you want to have an index with

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Seb via Digitalmars-d-learn
On Thursday, 8 June 2017 at 01:57:47 UTC, Andrew Edwards wrote: Ranges may be finite or infinite but, while the destination may be unreachable, we can definitely tell how far we've traveled. So why doesn't this work? ... If I hand you a chihuahua for grooming, why am I getting back a pit

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, June 08, 2017 02:31:43 Stanislav Blinov via Digitalmars-d-learn wrote: > On Thursday, 8 June 2017 at 02:25:17 UTC, Jonathan M Davis wrote: > > Oh I see, the was error related to iteration, not sorting. > > > Ranges do not support iterating with an index. The workaround > > if you

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 8 June 2017 at 02:25:17 UTC, Jonathan M Davis wrote: Oh I see, the was error related to iteration, not sorting. Ranges do not support iterating with an index. The workaround if you want to have an index with ranges and foreach, then you should use lockstep:

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, June 08, 2017 01:57:47 Andrew Edwards via Digitalmars-d-learn wrote: > Ranges may be finite or infinite but, while the destination may > be unreachable, we can definitely tell how far we've traveled. So > why doesn't this work? > > import std.traits; > import std.range; > > void

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Andrew Edwards via Digitalmars-d-learn
On Thursday, 8 June 2017 at 02:21:03 UTC, Stanislav Blinov wrote: aa.keys.sort() should just work as is: aa.keys returns a string[], and that's a random access range that can be sorted. What exactly is the error? It does not ... I provided the code and related error message. See the line

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 8 June 2017 at 01:57:47 UTC, Andrew Edwards wrote: Ranges may be finite or infinite but, while the destination may be unreachable, we can definitely tell how far we've traveled. So why doesn't this work? import std.traits; import std.range; void main() { string[string] aa;

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Andrew Edwards via Digitalmars-d-learn
On Thursday, 8 June 2017 at 02:19:15 UTC, Andrew Edwards wrote: Pretty funny. But seriously, this is something that just work. There is now to layers of indirection to achieve what I used to do quite naturally in the language. *should just work

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Andrew Edwards via Digitalmars-d-learn
On Thursday, 8 June 2017 at 02:07:07 UTC, Mike B Johnson wrote: On Thursday, 8 June 2017 at 01:57:47 UTC, Andrew Edwards wrote: If I hand you a chihuahua for grooming, why am I getting back a pit bull? I simply want a groomed chihuahua. Why do I need to consult a wizard to get back a groomed

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Mike B Johnson via Digitalmars-d-learn
On Thursday, 8 June 2017 at 01:57:47 UTC, Andrew Edwards wrote: If I hand you a chihuahua for grooming, why am I getting back a pit bull? I simply want a groomed chihuahua. Why do I need to consult a wizard to get back a groomed chihuahua? Because is like a poodle and unless you get your hair