From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: zsh-users@zsh.org
Subject: Re: How to impose a numeric sort on negative numbers?
Date: Tue, 7 Jul 2020 16:14:51 +0000 [thread overview]
Message-ID: <20200707161451.2a62fb22@tarpaulin.shahaf.local2> (raw)
In-Reply-To: <d3a75b03-31e8-4640-9725-0b9e26d053e9@www.fastmail.com>
Daniel Shahaf wrote on Fri, 03 Jul 2020 22:23 +0000:
> > 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.
The following patch addresses the first issue and documents "+42" as a
possible future extension.
Cheers,
Daniel
diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo
index 41ad967b2..21ecf9d6e 100644
--- a/Doc/Zsh/expn.yo
+++ b/Doc/Zsh/expn.yo
@@ -1092,15 +1092,18 @@ Convert all letters in the result to lower case.
item(tt(n))(
Sort decimal integers numerically; if the first differing
characters of two test strings are not digits, sorting
-is lexical. Integers with more initial zeroes
-are sorted before those with fewer or none. Hence the array `tt(foo1 foo02
+is lexical. `tt(+)' and `tt(-)' are not treated specially; they are treated as
+any other non-digit. Integers with more initial zeroes
+are sorted before those with fewer or none. Hence the array `tt(foo+24 foo1 foo02
foo2 foo3 foo20 foo23)' is sorted into the order shown.
May be combined with `tt(i)' or `tt(O)'.
)
item(tt(-))(
As tt(n), but a leading minus sign indicates a negative decimal
-integer. A `tt(-)' not followed by an integer does not trigger
+integer. A leading minus sign not followed by an integer does not trigger
numeric sorting.
+Note that `tt(+)' signs are not handled specially (this may change in the
+future).
)
item(tt(o))(
Sort the resulting words in ascending order; if this appears on its
next prev parent reply other threads:[~2020-07-07 16:15 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-01 17:45 Sebastian Gniazdowski
2020-07-01 18:02 ` Mikael Magnusson
2020-07-01 18:07 ` Sebastian Gniazdowski
2020-07-01 18:12 ` Roman Perepelitsa
2020-07-03 18:12 ` Lewis Butler
2020-07-03 18:35 ` Bart Schaefer
2020-07-01 19:42 ` Peter Stephenson
2020-07-02 11:36 ` Daniel Shahaf
2020-07-02 12:00 ` Peter Stephenson
2020-07-03 16:21 ` Hyphens, minuses, and dashes (was: Re: How to impose a numeric sort on negative numbers?) Daniel Shahaf
2020-07-02 15:46 ` How to impose a numeric sort on negative numbers? Bart Schaefer
2020-07-03 20:08 ` Peter Stephenson
2020-07-03 20:15 ` Bart Schaefer
2020-07-03 22:23 ` Daniel Shahaf
2020-07-07 16:14 ` Daniel Shahaf [this message]
2020-07-07 16:18 ` Daniel Shahaf
2020-07-01 18:48 ` Lawrence Velázquez
2020-07-06 7:15 ` Sebastian Gniazdowski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200707161451.2a62fb22@tarpaulin.shahaf.local2 \
--to=d.s@daniel.shahaf.name \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).