zsh-users
 help / color / mirror / code / Atom feed
* Is this a bug, doc error, or misunderstanding?
@ 2011-12-29 22:50 Larry Schrof
  2011-12-29 23:11 ` Larry Schrof
  2011-12-29 23:28 ` Vincent Lefevre
  0 siblings, 2 replies; 3+ messages in thread
From: Larry Schrof @ 2011-12-29 22:50 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 1310 bytes --]

>From the zshexpn man page under 'Parameter Expansion Flags' section:

   n      Sort decimal integers numerically; if the first  differing  charac-
          ters  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 ‘foo1 foo02 foo2 foo3 foo20 foo23’
          is sorted into the order shown.  May be combined with ‘i’ or ‘O’.

So that tells me that as two elements are being compared, and the sort hits the
first occurrence of two differing characters, AND those characters are not
digits, sort the entries lexiographically.

$ VAR=(ZHOST40 HOST+ host04 host4 host36)

I would expect this, using the (n) expansion flag, to sort to:
HOST+ ZHOST40 host04 host4 host36

This is because when comparing 'ZHOST40' and 'host04', 'Z' comes before 'h'
lexiographically. However, this is not what we get...

$ echo ${(n)VAR}
HOST+ host04 host4 host36 ZHOST40

It appears as if the (n) flag in this case applied an implicit case-insensitive
flag (i), which is not what I wanted.

Is this a bug in the (n) expansion flag, an erroneous explanation in the man page,
or just something fundamental thing I'm not getting?

Thanks!

P.S. Zsh version 4.3.10




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Is this a bug, doc error, or misunderstanding?
  2011-12-29 22:50 Is this a bug, doc error, or misunderstanding? Larry Schrof
@ 2011-12-29 23:11 ` Larry Schrof
  2011-12-29 23:28 ` Vincent Lefevre
  1 sibling, 0 replies; 3+ messages in thread
From: Larry Schrof @ 2011-12-29 23:11 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 2296 bytes --]

I think I answered my own question after brainstorming with some co-workers.

I believe my locale is forcing sorting to be case-insensitive (This is hinted at
in the (o) expansion flag):

$ LANG=en_US.UTF-8
$ locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
$ VAR=(a b c X x Y y Z z)
echo ${(n)VAR}
a b c x X y Y z Z
$ LC_COLLATE=C
echo ${(n)VAR}
X Y Z a b c x y z

Looks like setting 'LC_COLLATE' helps solve my problem!


From: ls <larrys@fb.com<mailto:larrys@fb.com>>
Date: Thu, 29 Dec 2011 14:50:37 -0800
To: "zsh-users@zsh.org<mailto:zsh-users@zsh.org>" <zsh-users@zsh.org<mailto:zsh-users@zsh.org>>
Subject: Is this a bug, doc error, or misunderstanding?

>From the zshexpn man page under 'Parameter Expansion Flags' section:

   n      Sort decimal integers numerically; if the first  differing  charac-
          ters  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 ‘foo1 foo02 foo2 foo3 foo20 foo23’
          is sorted into the order shown.  May be combined with ‘i’ or ‘O’.

So that tells me that as two elements are being compared, and the sort hits the
first occurrence of two differing characters, AND those characters are not
digits, sort the entries lexiographically.

$ VAR=(ZHOST40 HOST+ host04 host4 host36)

I would expect this, using the (n) expansion flag, to sort to:
HOST+ ZHOST40 host04 host4 host36

This is because when comparing 'ZHOST40' and 'host04', 'Z' comes before 'h'
lexiographically. However, this is not what we get...

$ echo ${(n)VAR}
HOST+ host04 host4 host36 ZHOST40

It appears as if the (n) flag in this case applied an implicit case-insensitive
flag (i), which is not what I wanted.

Is this a bug in the (n) expansion flag, an erroneous explanation in the man page,
or just something fundamental thing I'm not getting?

Thanks!

P.S. Zsh version 4.3.10




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Is this a bug, doc error, or misunderstanding?
  2011-12-29 22:50 Is this a bug, doc error, or misunderstanding? Larry Schrof
  2011-12-29 23:11 ` Larry Schrof
@ 2011-12-29 23:28 ` Vincent Lefevre
  1 sibling, 0 replies; 3+ messages in thread
From: Vincent Lefevre @ 2011-12-29 23:28 UTC (permalink / raw)
  To: zsh-users

On 2011-12-29 22:50:38 +0000, Larry Schrof wrote:
> This is because when comparing 'ZHOST40' and 'host04', 'Z' comes before 'h'
> lexiographically.

Not in all the locales.

xvii% VAR=(ZHOST40 HOST+ host04 host4 host36)
xvii% LC_ALL=C
xvii% echo ${(n)VAR}
HOST+ ZHOST40 host04 host4 host36
xvii% LC_ALL=fr_FR  
xvii% echo ${(n)VAR}
HOST+ host04 host4 host36 ZHOST40

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Arénaire project (LIP, ENS-Lyon)


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-12-29 23:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-29 22:50 Is this a bug, doc error, or misunderstanding? Larry Schrof
2011-12-29 23:11 ` Larry Schrof
2011-12-29 23:28 ` Vincent Lefevre

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).