Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: How to impose a numeric sort on negative numbers?



(Dangit, I'm not getting Peter's mail again)

On Thu, Jul 2, 2020 at 4:38 AM Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
>
> Peter Stephenson wrote on Wed, 01 Jul 2020 20:42 +0100:
> > +++ b/Doc/Zsh/expn.yo
> > @@ -1097,6 +1097,11 @@ are sorted before those with fewer or none.  Hence the array `tt(foo1 foo02
> >  foo2 foo3 foo20 foo23)' is sorted into the order shown.
> >  May be combined with `tt(i)' or `tt(O)'.
> >  )
> > +item(tt(DASH()))(
> > +As tt(n), but a leading minus sign indicates a negative decimal
> > +integer.  A solo `tt(DASH())' not followed by an integer does
> > +not trigger numeric sorting.
> > +)

It might be possible to change this.  For numeric sort, the function
eltpcmp() in sort.c ignores everything other than digits that compares
the same in any pair of the strings.  It could recognize a leading
hyphen as special.

The questionable thing is what to do about embedded hyphens.  If I'm
asked to sort (1-5 1-3, 1-4 1-2) numerically, what does the hyphen
mean?  Right now it's just ignored.  Reverse the order of the sort
every time we encounter a hyphen?



Messages sorted by: Reverse Date, Date, Thread, Author