Bill Allombert on Tue, 20 Feb 2018 14:59:09 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: vecsort() and sign()


On Tue, Feb 20, 2018 at 11:27:12AM +0100, Karim Belabas wrote:
> This is historical: a long time ago, the comparison function was
> required to return 1, 0 or -1. The sign function is now useless for
> vecsort, I have updated the documentation.
> 
> > Also, the build-in help for vecsort() says:
> > "If cmpf is an integer, sort according to the value of the k-th component
> > of each entry."
> > First, it's not clear what is k here. Perhaps, it should say "if cmpf
> > equals an integer *k*" or something like that.
> 
> Done ! In fact, this is a rather useless construct since it's trivial to
> emulate it with (x,y)->x[k]-y[k]. A much more useful one is k = [1,3,2]
> (sort by 1st entry, then 3rd, then 2nd: this one is more painful to emulate
> with a closure...).

We could also allow cmpf to be a closure with arity 1 and then use
(x,y)->cmp(cmpf(x),cmpf(y)) as a comparaison function.

Cheers,
Bill.