October 17, 2012
On 10/15/12 9:29 PM, Mehrdad wrote:
> Hmm, I didn't know 'sort' returns a value. That's very confusing
> since now I have no idea if it's mutating or not. Python has both
> sort and sorted, with clear meanings. (The goal was to make a
> non-mutating version that I could call functional.) Maybe we
> should clarify what sort exactly does and doesn't do...

std.algorithm operates in place wherever possible, and sort's result is a view on the same range as the original, but with new capabilities created by the sorting process. I think it's a very elegant design.

October 17, 2012
On 10/15/12 9:47 PM, Jonathan M Davis wrote:
> And if SortedRange is changed to provide access to its underlying range via a
> member named source (it was recently suggested by Andrei that we should
> standardize on doing that where appropriate), then it could become a one-
> liner:
> auto result = sort(array(range)).source;

Yes, I think we should move toward the ".source" convention for all applicable ranges, e.g. retro.source yields the original range etc.


October 17, 2012
On 10/15/12 10:35 PM, Mehrdad wrote:
> On Tuesday, 16 October 2012 at 01:47:58 UTC, Jonathan M Davis wrote:
>> It should probably explain the rationale behind returning SortedRange
>> so that it's much clearer as to why you'd want to use the return value
>> rather than the original (now sorted) range.
> +1
> As it stands it's not at all clear from the documentation what the
> intention is, or how someone can go about sorting something without
> mutating it.
> Thanks for the responses.

Agreed. Part of the problem was that at the time I changed sort to return a value (it used to return void), severe compiler bugs forced me to take it out again for a while. So it's been "experimental" until it just silently started working and I forgot about it; and you know how documentation of experimental work goes...

Regarding sorted(), one possibility would be to define a lazy sorting routine under that name or lazySort(). It would make for a better name than heap(), which implements the desired functionality.

Next ›   Last »
1 2