From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27278 invoked by alias); 31 May 2017 21:25:04 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 41186 Received: (qmail 21151 invoked from network); 31 May 2017 21:25:04 -0000 X-Qmail-Scanner-Diagnostics: from mail-wm0-f47.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(74.125.82.47):SA:0(0.5/5.0):. Processed in 1.170579 secs); 31 May 2017 21:25:04 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=0.5 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RCVD_IN_SORBS_SPAM, SPF_PASS,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.1 X-Envelope-From: stephane.chazelas@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 74.125.82.47 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mail-followup-to:mime-version :content-disposition:content-transfer-encoding:user-agent; bh=s4QJYeO64iNRO/20Oei5tk5VIb9RchFWmwrMWP8pxrA=; b=jiNUwPWuZQEY+cxJoRexk40YmF1t4ZQWJm66o9R0R3S7vt67rXnG6GHHQMcangJxbU /vhMZFimny5kHHWek+oRw030gVvvVh7glriF6kSJJbOe0ZSBsM/IvW9f2XL/QwmGBkiR xW33GPyC72dxqVD4lyZzklB0nN+WpITfx101WgL4Ne4DmQdhD2wcMKrexv64Lf97MyFs fuHB64bhx8iTUZCWvP4CrVnkymfNDcssiAIprnBH/XhDmyfDMfWM7fRKGJWxpMOho69N rSxJrWi9muASMZbiyhQ5E/ScR94sriZkzm+miCgJ0lan+ZBaVBtG4kgXy4iqAVyYwNHh ADzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mail-followup-to :mime-version:content-disposition:content-transfer-encoding :user-agent; bh=s4QJYeO64iNRO/20Oei5tk5VIb9RchFWmwrMWP8pxrA=; b=gVgk4GzZEIj8Bae5DONE16915tvrxqVlUB8kelvtsdCH/I/7fOFi42qrJC7ygPn/6F vTykjTuD119EvuxwU8FP1lZ5yIbODd6a3ptr7AW7rUTzj6Gph01fVWC7HcJD2qk//EJQ H+LiPB6ZIrLGYICluKAkhHXx7sWr7B/YKljSaY//JVlwXGycqAJkxLE0TTR6s6JtVbPk gScq2jSrtj0e939jMeGJWFkD1oui2iSApTOSmoz0ZsddsRY94a3IQhnCDDje7KBlUQRs t6wWkMWu4xmdAdNUyF4S5g3m2h2Eo/YexUcrk616mMZoetA4PKUInTwelh5hrIuHdziI SBEQ== X-Gm-Message-State: AODbwcBL5JS/5wY12QdOhZP6SaqzpAFbx/c/2fTXwA9jjs5tSxt3Ut+L tTlfookwirBMGk38 X-Received: by 10.28.55.84 with SMTP id e81mr7147204wma.36.1496265896137; Wed, 31 May 2017 14:24:56 -0700 (PDT) Date: Wed, 31 May 2017 22:24:53 +0100 From: Stephane Chazelas To: Zsh hackers list Subject: Surprising behaviour with numeric glob sort Message-ID: <20170531212453.GA31563@chaz.gmail.com> Mail-Followup-To: Zsh hackers list MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.5.24 (2015-08-30) Some odd behaviour: $ echo *(n) a3 a10 a-2 $ rm a10 $ echo *(n) a-2 a3 (order of a-2 and a3 reversed after a10 is removed) $ echo $LANG en_GB.UTF-8 $ /lib/x86_64-linux-gnu/libc.so.6 GNU C Library (Ubuntu GLIBC 2.23-0ubuntu7) stable release version 2.23, by Roland McGrath et al. I think the problem is that here, zsh uses a non-total order. We have: a3 < a10 (same prefix, so numeric comparison of 3 < 10) a10 < a-2 (as per strcoll(). - ignored in first pass. No same prefix, so no numeric comparison) a-2 < a3 (as per strcoll(). - ignored in first pass. No same prefix, so no numeric comparison) We've got a circle here. AFAIK, the behaviour is unspecified if qsort() is called with a comparison function that doesn't implement a total order, so the result could be random. Once we remove a10, we're OK. GNU sort -V and ls -v seem to "handle" the issue by giving up on strcoll() which is not a lot better: $ ls a0 á0 a10 a-2 a3 b0 $ ls -v a0 a3 a10 a-2 b0 á0 $ ls | sort a0 á0 a10 a-2 a3 b0 $ ls | sort -V a0 a3 a10 a-2 b0 á0 Maybe a better approach would be to break down the strings between non-numeric and numeric parts and use strcoll() on the non-numeric and number comparison on the numeric parts, stopping at the first difference. a3 < a-2 because a < a- as per strcoll (even though a3 > 1-2) -- Stephane