Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: reverse numeric sorting does not work
- X-seq: zsh-workers 23660
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: Re: reverse numeric sorting does not work
- Date: Fri, 6 Jul 2007 14:04:30 +0100
- In-reply-to: <20070706122415.GG18533@xxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- Organization: CSR
- References: <20070706122415.GG18533@xxxxxxxxxxxxxxxxxxx>
On Fri, 6 Jul 2007 14:24:15 +0200
Vincent Lefevre <vincent@xxxxxxxxxx> wrote:
> Reverse numeric sorting doesn't seem to work:
Yes: failure in test strategy (there isn't a test).
> Also the man page is ambiguous:
>
> Are the numbers (nonnegative) integer or floating-point numbers?
Yes, 3.3 is also a "decimal number" but isn't sorted after the ".".
> It also says: "if the first differing characters of two test strings
> are not digits, sorting is lexical." then "Trailing non-digits are
> not sorted; the order of `2foo' and `2bar' is not defined." But on
> this example, the first differing characters are not digits, so that
> the sorting should be lexical, hence defined!
Given that 02 and 2 are defined to sort in that order (I've been more picky
about the wording with leading zeroes to cover all bases), that doesn't
seem to leave anything for that second sentence to cover: either the first
differing part is an integer, in which case there's a defined order even if
two different sets of digits are numerically equal (proof by grabbing a
first year maths student), or the first different part is not numerical, in
which case sorting is lexical. So I've omitted it.
Index: Doc/Zsh/expn.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/expn.yo,v
retrieving revision 1.78
diff -u -r1.78 expn.yo
--- Doc/Zsh/expn.yo 30 May 2007 03:08:22 -0000 1.78
+++ Doc/Zsh/expn.yo 6 Jul 2007 12:59:41 -0000
@@ -764,13 +764,12 @@
Convert all letters in the result to lower case.
)
item(tt(n))(
-Sort decimal numbers numerically; if the first differing
+Sort decimal integers numerically; if the first differing
characters of two test strings are not digits, sorting
-is lexical. Numbers with initial zeroes
-are sorted before those without. Hence the array `tt(foo1 foo02
-foo2 foo3 foo20 foo23)' is sorted into the order shown. Trailing
-non-digits are not sorted; the order of `tt(2foo)' and `tt(2bar)'
-is not defined. May be combined with `tt(i)' or `tt(O)'.
+is lexical. Integers with more initial zeroes
+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(o))(
Sort the resulting words in ascending order; if this appears on its
Index: Src/sort.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/sort.c,v
retrieving revision 1.6
diff -u -r1.6 sort.c
--- Src/sort.c 13 May 2007 20:22:02 -0000 1.6
+++ Src/sort.c 6 Jul 2007 12:59:43 -0000
@@ -134,9 +134,9 @@
while (idigit(*as) && idigit(*bs))
as++, bs++;
if (idigit(*as) && !idigit(*bs))
- return 1;
+ return sortdir;
if (idigit(*bs) && !idigit(*as))
- return -1;
+ return -sortdir;
}
}
}
Index: Test/D04parameter.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/D04parameter.ztst,v
retrieving revision 1.25
diff -u -r1.25 D04parameter.ztst
--- Test/D04parameter.ztst 13 Apr 2007 11:54:17 -0000 1.25
+++ Test/D04parameter.ztst 6 Jul 2007 12:59:43 -0000
@@ -913,3 +913,10 @@
>AXB C1D
>AB C0D
>AB C0D
+
+ foo=(a6 a117 a17 b6 b117 b17)
+ print ${(n)foo}
+ print ${(On)foo}
+0:Numeric sorting
+>a6 a17 a117 b6 b17 b117
+>b117 b17 b6 a117 a17 a6
--
Peter Stephenson <pws@xxxxxxx> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
To access the latest news from CSR copy this link into a web browser: http://www.csr.com/email_sig.php
To get further information regarding CSR, please visit our Investor Relations page at http://ir.csr.com/csr/about/overview
Messages sorted by:
Reverse Date,
Date,
Thread,
Author