From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 29828 invoked from network); 3 Jul 2020 22:24:48 -0000 Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 3 Jul 2020 22:24:48 -0000 Received: (qmail 6276 invoked by alias); 3 Jul 2020 22:24:38 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: Sender: zsh-users@zsh.org X-Seq: 24980 Received: (qmail 3328 invoked by uid 1010); 3 Jul 2020 22:24:38 -0000 X-Qmail-Scanner-Diagnostics: from out2-smtp.messagingengine.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.3/25857. spamassassin: 3.4.4. Clear:RC:0(66.111.4.26):SA:0(-2.6/5.0):. Processed in 4.960711 secs); 03 Jul 2020 22:24:38 -0000 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at daniel.shahaf.name does not designate permitted sender hosts) X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedrtdejgddtlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepofgfggfkjghffffhvffutgesthdtre dtreertdenucfhrhhomhepfdffrghnihgvlhcuufhhrghhrghffdcuoegurdhssegurghn ihgvlhdrshhhrghhrghfrdhnrghmvgeqnecuggftrfgrthhtvghrnhepjeeuveehueekje dtffegveelhfethefhlefhfffgudeuhfdtvdehhfejkeeghedtnecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepugdrshesuggrnhhivghlrdhshh grhhgrfhdrnhgrmhgv X-ME-Proxy: X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.3.0-dev0-576-gfe2cd66-fm-20200629.001-gfe2cd668 Mime-Version: 1.0 Message-Id: In-Reply-To: <3f4d22d506fc069965c1e37d0f06ee585a5073dc.camel@ntlworld.com> References: <3580763ca2a81e24786f92071be073833b820b83.camel@ntlworld.com> <20200702113640.3343ff0c@tarpaulin.shahaf.local2> <3f4d22d506fc069965c1e37d0f06ee585a5073dc.camel@ntlworld.com> Date: Fri, 03 Jul 2020 22:23:35 +0000 From: "Daniel Shahaf" To: zsh-users@zsh.org Subject: Re: How to impose a numeric sort on negative numbers? Content-Type: text/plain Peter Stephenson wrote on Fri, 03 Jul 2020 20:08 +00:00: > On Thu, 2020-07-02 at 08:46 -0700, Bart Schaefer 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. > > (I've committed it with DASH() turned into -.) > (Turns out there were five instances of tt(DASH()), not two as I implied in my review, so I've gone ahead and changed those as well.) > The doc was just to record the fact that I didn't treat a "-" as "-0", > just as a character "-". That was a deliberate choice --- I'm > assuming the usual case of a numeric sort will have at least one > decimal digit in the part to be sorted and anything else is > just a hyphen (and definitely not a dash). FWIW, I thought at first reading that that second sentence referred to the `tt(-)' in the parameter expansion flags, not to the one in the input data. I'd never have expected "-" or "-foo" to be considered an integer in the first place, just like "" and "foo" aren't considered integers. Incidentally, should "+42" be sorted as an integer? Right now it isn't. Cheers, Daniel