Re: [julia-users] calling sort on a range with rev=true

2016-05-04 Thread 'Greg Plowman' via julia-users
Thanks Steven for fixing this.

(If you pass them keyword arguments, then they pretty much have to return a 
> full array, rather than try to be clever and return another range, for 
> type-stability.  e.g. sort(-5:5, by=abs) can't be expressed in terms of a 
> range.)


At first I didn't understand this, until I came around to understanding 
that keyword arguments don't participate in dispatch.
So it's not possible to specialise on a *particular* keyword. It's all or 
nothing.
I guess this make keyword arguments slightly less useful in some 
circumstances.

For my purpose, I defined my own reverse sort so that I could specialise:

sortrev(v::AbstractVector) = sort(v, rev=true)
sortrev(r::Range) = issorted(r) ? reverse(r) : r



Re: [julia-users] calling sort on a range with rev=true

2016-05-02 Thread Steven G. Johnson
The case of sort and select are fixed here:

   https://github.com/JuliaLang/julia/pull/16168

(If you pass them keyword arguments, then they pretty much have to return a 
full array, rather than try to be clever and return another range, for 
type-stability.  e.g. sort(-5:5, by=abs) can't be expressed in terms of a 
range.)


Re: [julia-users] calling sort on a range with rev=true

2016-05-01 Thread Tamas Papp
On Mon, May 02 2016, via julia-users wrote:

> I guess it's unclear whether sort(1:3, rev=true) should return 3:-1:1 or
> [3,2,1] or be an error as it currently is.

IMO in general, all pure (non-modifying) functions that operate on
objects that are isomorphic to vectors should

1) accept all representations that collect can handle (by possibly
falling back to it), and

2) be allowed to return any representation they find convenient.

Users who want a specific form (eg a Vector) should convert
themselves. So the optimal choice would be 3:-1:1 for performance, but
users should not rely on this, and write code that would work for
[3,2,1] too.

Best,

Tamas


[julia-users] calling sort on a range with rev=true

2016-05-01 Thread 'Greg Plowman' via julia-users

There have been discussions about whether a range can substitute in most 
cases where a vector is required.

julia> sort(1:3)
1:3

julia> sort(1:3, rev=true)
ERROR: indexed assignment not defined for UnitRange{Int64}
 in sort! at sort.jl:222
 in sort! at sort.jl:292
 in sort! at sort.jl:402
 in sort at sort.jl:413

julia> sort(collect(1:3), rev=true)
3-element Array{Int64,1}:
 3
 2
 1



I guess it's unclear whether sort(1:3, rev=true) should return 3:-1:1 or 
[3,2,1] or be an error as it currently is.

Any thoughts?