zsh-users
 help / color / mirror / code / Atom feed
From: Ray Andrews <rayandrews@eastlink.ca>
To: zsh-users@zsh.org
Subject: Re: triviality regarding $# counts
Date: Sun, 14 Apr 2024 06:24:11 -0700	[thread overview]
Message-ID: <4e9aa98c-9b5d-4e22-b7fc-8c50a9af9ada@eastlink.ca> (raw)
In-Reply-To: <CAH+w=7YJFeEnG3Ha1rcH45p=y2xObJDpfdxKrbR=0Y-E49hZcA@mail.gmail.com>

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



On 2024-04-13 21:57, Bart Schaefer wrote:
> Because zsh does not split parameter expansions by default, $ary and
> $ary[*] and $ary[@] are equivalent when not quoted, as Lawrence
> demonstrated.
>
> However, in all three of those cases, empty elements are typically
> discarded, as they would be in a shell that defaults to splitting.
> That's why "$ary[@]" is still useful:  It quotes each element
> individually, so empty elements are preserved.
>
> (Aside, in bash and ksh, $ary is equivalent to ${ary[0]}, not to
> ${ary[*]}.  A little oddly, this is also true for their associative
> arrays, that is, the value for key 0 is used.)
I know it's far too late to fret this stuff, still it's interesting to 
contemplate these design level issues.  P.F. did the right thing not 
splitting by default but he should have left the empties in by default 
too, IMHO.  Options should be positive not negative as a fundamental 
principle.  Don't do helpful things automatically, and force me to stop 
you from doing them.  Much better to leave things alone, and if I want, 
say, empty elements removed, I'll ask for them to be removed.  A=B 
should mean that A is identical to B, not B with blanks removed, nor 
sorted, nor capitalized, nor duplicates removed, nor checked for 
spelling, nor ... nothing.

"$ary[@]" should be the default with some ${(?)...} flag to indicate 
that I'd like blanks removed or  duplicates or ... whatever massaging 
I'd want.  Cool that all those manipulations are available of course, 
but as Raymond Sensei  (E. S. Raymond) explains so well, the 'doctrine 
of least surprise' should prevail.  Equals equals equals, not 'equals 
minus blanks'.  So we have:

aaa=( "${(@f)bbb}" )

... which is code fighting itself.  The quotes normally mean 'join 
together' but they also mean 'preserve spaces' and so then '(@f)' 
contradicts the joining so we retain multiple elements.  IMHO it should 
look like this:

aaa=( $bbb )

Equals equals equals.

But as we have  it:

----------------------------------------------------------------------------------

% print $ddd
abc     def ghi     jkl mno     pqr

% fff=( $ddd )

% print $fff
abc     def ghi     jkl mno     pqr

# Looks ok, donit? But don't be a chump:

% typeset -p ddd; typeset -p fff
typeset -a ddd=( '' abc '' $'\tdef ghi' $'\tjkl mno' '' $'\tpqr' '' )
typeset -a fff=( abc $'\tdef ghi' $'\tjkl mno' $'\tpqr' )

# It's not a zebra, it's a horse with painted stripes!
# If you want a COPY ... yes, a Xerox copy:

% fff=( "${(@f)ddd}" )

% typeset -p ddd; typeset -p fff
typeset -a ddd=( '' abc '' $'\tdef ghi' $'\tjkl mno' '' $'\tpqr' '' )
typeset -a fff=( '' abc '' $'\tdef ghi' $'\tjkl mno' '' $'\tpqr' '' )

# That's a COPY ... and don't even think about a simpler way, we are on 
this earth to suffer.

------------------------------------------------------------------------------------

Just sayin', I know there's nothing to be done about it now.



[-- Attachment #2: Type: text/html, Size: 4000 bytes --]

  reply	other threads:[~2024-04-14 13:25 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-11  0:56 Ray Andrews
2024-04-12  4:55 ` Lawrence Velázquez
2024-04-12 14:48   ` Ray Andrews
2024-04-12 19:09     ` Bart Schaefer
2024-04-13  1:13       ` Ray Andrews
2024-04-13  1:33         ` Mark J. Reed
2024-04-13  2:28           ` Ray Andrews
2024-04-13  3:25             ` Lawrence Velázquez
2024-04-13 14:37               ` Ray Andrews
2024-04-13 15:14                 ` Ray Andrews
2024-04-13 17:19                   ` Mark J. Reed
2024-04-13 17:27                     ` Mark J. Reed
2024-04-13 18:08                       ` Ray Andrews
2024-04-13 19:45                         ` Bart Schaefer
2024-04-13 20:36                           ` Ray Andrews
2024-04-13 21:01                             ` Bart Schaefer
2024-04-14  0:28                               ` Ray Andrews
2024-04-14  0:30                               ` Lawrence Velázquez
2024-04-14  3:26                                 ` Ray Andrews
2024-04-14  3:49                                   ` Lawrence Velázquez
2024-04-14  4:57                                     ` Bart Schaefer
2024-04-14 13:24                                       ` Ray Andrews [this message]
2024-04-14 13:35                                         ` Roman Perepelitsa
2024-04-14 14:06                                           ` Ray Andrews
2024-04-14 14:15                                             ` Roman Perepelitsa
2024-04-14 14:53                                               ` Ray Andrews
2024-04-14 15:11                                                 ` Mark J. Reed
2024-04-14 16:23                                                   ` Ray Andrews
2024-04-14 14:06                                         ` Mark J. Reed
2024-04-14 14:47                                           ` Ray Andrews
2024-04-14 14:59                                             ` Mark J. Reed
2024-04-14 15:51                                         ` Bart Schaefer
2024-04-14 17:22                                           ` Ray Andrews
2024-04-14 17:42                                             ` Mark J. Reed
2024-04-14 18:24                                               ` Bart Schaefer
2024-04-14 22:00                                               ` Ray Andrews
2024-04-13 20:11                         ` Mark J. Reed
2024-04-13 20:53                   ` Bart Schaefer
2024-04-14  0:19                     ` Ray Andrews
2024-04-13  1:35         ` Bart Schaefer

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=4e9aa98c-9b5d-4e22-b7fc-8c50a9af9ada@eastlink.ca \
    --to=rayandrews@eastlink.ca \
    --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).