From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3737 invoked from network); 6 Jul 2007 13:04:51 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.1 (2007-05-02) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.1 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 6 Jul 2007 13:04:51 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 74226 invoked from network); 6 Jul 2007 13:04:45 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 6 Jul 2007 13:04:45 -0000 Received: (qmail 1576 invoked by alias); 6 Jul 2007 13:04:42 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 23660 Received: (qmail 1567 invoked from network); 6 Jul 2007 13:04:40 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 6 Jul 2007 13:04:40 -0000 Received: (qmail 73877 invoked from network); 6 Jul 2007 13:04:40 -0000 Received: from cluster-d.mailcontrol.com (217.69.20.190) by a.mx.sunsite.dk with SMTP; 6 Jul 2007 13:04:34 -0000 Received: from cameurexb01.EUROPE.ROOT.PRI ([62.189.241.200]) by rly39d.srv.mailcontrol.com (MailControl) with ESMTP id l66D4Ubu025896 for ; Fri, 6 Jul 2007 14:04:31 +0100 Received: from news01.csr.com ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.1830); Fri, 6 Jul 2007 14:04:30 +0100 Date: Fri, 6 Jul 2007 14:04:30 +0100 From: Peter Stephenson To: zsh-workers@sunsite.dk Subject: Re: reverse numeric sorting does not work Message-ID: <20070706140430.27190c75@news01.csr.com> In-Reply-To: <20070706122415.GG18533@prunille.vinc17.org> References: <20070706122415.GG18533@prunille.vinc17.org> Organization: CSR X-Mailer: Claws Mail 2.9.1 (GTK+ 2.10.12; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 06 Jul 2007 13:04:30.0352 (UTC) FILETIME=[30A33900:01C7BFCE] X-Scanned-By: MailControl A-07-07-10 (www.mailcontrol.com) on 10.68.0.149 On Fri, 6 Jul 2007 14:24:15 +0200 Vincent Lefevre 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 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