From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id 961E924744 for ; Sun, 14 Apr 2024 16:08:22 +0200 (CEST) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1713103702; b=p6mheefrCC00O/Gb1Bd+h3xb2bK+k9Z7UI1EPzAcTd+trZhUvJoQCgJuJU1W15HPNAHu+aQA1J XniFah0+A/ITa+E6P69lHYQUxCmYKJwb+IrXAmnRLQCR8QUvwaQK9UuiAGsEkTC79d7DmR8k9G bXm3aW5wnId1qPjNvlmwIqYCRUhZddv1uRPAnKDbSNTz+Z4WksnNI9kXAMGBvTFigDNWhN9ifS sGf/PlkRgZ3iwelfY93IrKpgbMiBkwASIWbaFRVFLJTbz1fQ8smOuuKxNIODZi8ND2gyJRQX/f PcFN12vacIyFtaLI3d8M5KUI3ezs2QSXySoyT7tMMxA31Q==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lj1-f176.google.com) smtp.remote-ip=209.85.208.176; dkim=pass header.d=gmail.com header.s=20230601 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1713103702; bh=/+MTsPZRuB7Gld7dFUk7ECqZ7lz+rVa5iYrrANEwjME=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=YCfh7F09JVGJowLtd+dCW5u62hertfnDVCtcZtX9ul3Wxkwp9wYdnmboUty4IO4VWpIVtoVSde 2lYGqR3YGsr1TxhAA9y6QpvFHLDmD4BitG6CIrTPNYeWpILy0A74hAxWlG+xzR5bie8Bd54/iM JcJStj/H4gnJMjMJRa98qlAW+5r/snXPRqwUmUrDOoWpfdtzRAAIs2O7tSsIG5aSeOF889+2lx MoEkPQvDim8+XydvD8WRLbRJKnc5tNEW19kt3UEXfcSDP3c/8AyXmjjA7/ypelvZsrqvoZU2RR xat+sA4EMNHz3icHgiqzyWvTwGmsUIOw9ZRmju/5FjjS2Q==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:To:Subject:Message-ID: Date:From:In-Reply-To:References:MIME-Version:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=9KWR2B4jAVImOGyEL3OZimEiOrov1cukIlIbPgaQY3w=; b=hFmldzySJIGbVRrhcxxHCkHg10 Kzn0bWnK5siQSuPze2YvRsRk3pt4yI7C3FVf053BDmRXegD3z72HUqygma15aqPTaKsZ3bhxFJtvf beeWhDw0sF32CSKvFJYjDnNYQ5AzyRAF75QfMc1b5AvQt9CFovjXqPh3YUq202aOZZVebqGmxMvjP HcJOktzjTZM83vJqwTSSvcT6SbhUjZUMYYHYSGq+YMgxi4WVweIr0op3uL2yy0f0FqeU2KCI/9pK3 FiVMqU8gwoj9bSc6v1rUNEPXBrUxqPr5maRhgyLYYWdXeNg2yenBJJZA9F31Uc8KTgRehtxuLe2s2 mrbBcZ4Q==; Received: by zero.zsh.org with local id 1rw0Ws-000Fyo-FK; Sun, 14 Apr 2024 14:08:22 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lj1-f176.google.com) smtp.remote-ip=209.85.208.176; dkim=pass header.d=gmail.com header.s=20230601 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-lj1-f176.google.com ([209.85.208.176]:43310) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rw0Vj-000F3s-4m; Sun, 14 Apr 2024 14:07:11 +0000 Received: by mail-lj1-f176.google.com with SMTP id 38308e7fff4ca-2d886f17740so37820371fa.1 for ; Sun, 14 Apr 2024 07:07:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713103630; x=1713708430; darn=zsh.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=9KWR2B4jAVImOGyEL3OZimEiOrov1cukIlIbPgaQY3w=; b=UJqWcTAPVSQEqVUH/U8I7x+2Pody7xb9fuRe5u0G0Igh78AWbhohnJL2OaeqzoiQZp oqJcAiwgCE6VfmZL3elzY5PJsS+5sAj7BvwLu6qMA0NduM3MAuefjPuj99cDWfa7/+70 mj/OITXRJ1Auu3h8vfln0JyRLZZm2LyX/aP87aaQ7iBWvWOcYKqx7AZMSoL+/DBW3L30 oGinm12LwbdZpHwRnfNn0hluP55zGDZQ9xhdXOKZ3jGSmIie3L8IzImCKB7udWlvC8tv vCRT0lOboBTEDY8EPlG4pbRy0iC2d2cswj9+MRFpLNEdFCtPCh9gBr+N/kG9WljD8uLg JHzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713103630; x=1713708430; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9KWR2B4jAVImOGyEL3OZimEiOrov1cukIlIbPgaQY3w=; b=S4lFPo0u2dLMKp283r4OiA6nagcemDaDACt+87lhvliZ0u8iNIr9arsb+o47nXXPcz bPcdnWacCKOOmfXAhVxxpZDI7bO8Q2P/HAFEuMMlsNiZ4GSWuSYAgMCjnkfv5icppQ6H CXUF6NTiPQ77xrBKGWGrGRydvOsWuAVA76k+ajCbqNLdSPvajFHl3HqMaNrLewITgHbT b59JSeYkxslqtz+sLAYqikB8JG5CQiq0CvAFORGnbLRF8LRjp4KoZ5mzBV2Qryiu+r44 qItF9iSSaJEtwj4ggVbLVU2TDlq8rZ7tl1ENe+229+CASkLVK+g1nBHp5oPcNt1otyiF CIQA== X-Gm-Message-State: AOJu0YwBp7mvHC0q1B881+yIskyaPmFoi9mA5K6HgrnHXZApfA43MBtF ujzYVQyzhFxBQb1OBY+OB3fO4Nk4am23G9/0ornqwRpNPrr/riBHPiMT0XQBAPgLq8hWx7O2Zix R9TyLMXPo+hFQJOTmn4U0MZEHV60V/e0tgiA= X-Google-Smtp-Source: AGHT+IErPGIKJ6KjGEVi/K384bLOyK7ouo8sPG6jz9xgxCd/ArNCjnvT2IatjOH6Fh+v0BnuFbiU+2iwx348MbOszuw= X-Received: by 2002:a2e:bb93:0:b0:2d8:3d7b:bd91 with SMTP id y19-20020a2ebb93000000b002d83d7bbd91mr1962704lje.18.1713103629546; Sun, 14 Apr 2024 07:07:09 -0700 (PDT) MIME-Version: 1.0 References: <97793422-1543-4ba6-b52b-ff93eba03ab1@eastlink.ca> <7333cf23-1fe7-4b3d-a7c1-f07697c5f062@eastlink.ca> <1e53a3f7-9bdb-45ae-81c7-7d0ec1a6a541@app.fastmail.com> <3cc19e86-e953-4e2f-9e57-30ff84f15fdf@eastlink.ca> <0a0b9ec3-4661-4386-9fbf-b3152a46001e@eastlink.ca> <9416dc0a-3e41-4229-a9e1-239411ab3c17@eastlink.ca> <4a1e027c-a9d8-4306-bf3b-e1282914644c@app.fastmail.com> <4e9aa98c-9b5d-4e22-b7fc-8c50a9af9ada@eastlink.ca> In-Reply-To: <4e9aa98c-9b5d-4e22-b7fc-8c50a9af9ada@eastlink.ca> From: "Mark J. Reed" Date: Sun, 14 Apr 2024 10:06:57 -0400 Message-ID: Subject: Re: triviality regarding $# counts To: Zsh Users Content-Type: multipart/alternative; boundary="0000000000004d7d0f06160f0558" X-Seq: 29821 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: --0000000000004d7d0f06160f0558 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable > > # It's not a zebra, it's a horse with painted stripes! > # If you want a COPY ... yes, a Xerox copy: > % fff=3D( "${(@f)ddd}" ) What? No. Why do you keep bringing (f) into this? That flag has nothing to do with copying; in fact it intentionally changes things: anywhere there used to be a single string containing a newline,you get two strings instead. But if you drop the f, you do get your Xerox copy: % fff=3D( "${(@)ddd}" ) Would it be nicer if you could just do *fff=3D$ddd* and not have to include the parens and quotes and @? Sure. You could even make a case that it *shou= ld *work that way, since we're in Zshland where *$ddd* expands to the whole array instead of a single element. But that's not the way assignment works. Though, as I said, if the array has no empty elements, you can get away with just *fff=3D($ddd)*. On Sun, Apr 14, 2024 at 9:24=E2=80=AFAM Ray Andrews wrote: > > > 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 to= o, > IMHO. Options should be positive not negative as a fundamental principle= . > Don't do helpful things automatically, and force me to stop you from doin= g > them. Much better to leave things alone, and if I want, say, empty > elements removed, I'll ask for them to be removed. A=3DB should mean tha= t 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=3D( "${(@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=3D( $bbb ) > > Equals equals equals. > > But as we have it: > > > -------------------------------------------------------------------------= --------- > > % print $ddd > abc def ghi jkl mno pqr > > % fff=3D( $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=3D( '' abc '' $'\tdef ghi' $'\tjkl mno' '' $'\tpqr' '' ) > typeset -a fff=3D( 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=3D( "${(@f)ddd}" ) > > % typeset -p ddd; typeset -p fff > typeset -a ddd=3D( '' abc '' $'\tdef ghi' $'\tjkl mno' '' $'\tpqr' '' ) > typeset -a fff=3D( '' 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. > > > > --=20 Mark J. Reed --0000000000004d7d0f06160f0558 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
# It's not a zebra, it's a horse with= painted stripes!
# If you = want a COPY ... yes, a Xerox copy:
% fff=3D( "${(@f)ddd}" )
What? No.=C2=A0 Why do you keep bringing (f) into this? That fl= ag has nothing to do with copying; in fact it intentionally=C2=A0changes th= ings: anywhere there used to be a single string containing a newline,you ge= t two strings instead.=C2=A0

But if you drop the f= , you do get your Xerox copy:

% fff=3D( "${(@)ddd}" )
=
Would i= t be nicer if you could just do fff=3D$ddd=C2=A0and not have to incl= ude the parens and quotes and=C2=A0@? Sure. You could even make a case that= it should work that way, since we're in Zshland=C2=A0where $= ddd expands to the whole array instead of a single element. But that= 9;s not the way assignment works. Though, as I said, if the array has no em= pty elements, you can get away with just fff=3D($ddd).

<= div>





On Sun, Apr 14, 2024 at 9:24=E2=80=AFAM Ray Andrews <rayandrews@eastlink.ca> wrote:
=20 =20 =20


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 interes= ting to contemplate these design level issues.=C2=A0 P.F. did the right thin= g not splitting by default but he should have left the empties in by default too, IMHO.=C2=A0 Options should be positive not negative as a fundamental principle.=C2=A0 Don't do helpful things automatically,= and force me to stop you from doing them.=C2=A0 Much better to leave things alone, and if I want, say, empty elements removed, I'll ask for the= m to be removed.=C2=A0 A=3DB 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.=C2=A0

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

aaa=3D( "${(@f)bbb}" )=C2=A0=C2=A0

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

aaa=3D( $bbb )

Equals equals equals.=C2=A0

But as we have=C2=A0 it:

---------------------------------------------------------------------------= -------

% print $ddd=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0
abc =C2=A0=C2=A0=C2=A0 def ghi =C2=A0=C2=A0=C2=A0 jkl mno =C2=A0=C2= =A0=C2=A0 pqr

% fff=3D( $ddd )=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0

% print $fff
abc =C2=A0=C2=A0=C2=A0 def ghi =C2=A0=C2=A0=C2=A0 jkl mno =C2=A0=C2= =A0=C2=A0 pqr

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

% typeset -p ddd; typeset -p fff
typeset -a ddd=3D( '' abc '' $'\tdef ghi' $&#= 39;\tjkl mno' '' $'\tpqr' '' )
typeset -a fff=3D( abc $'\tdef ghi' $'\tjkl mno' $= 9;\tpqr' )

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

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

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

# That's a COPY ... and don't e= ven 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.=C2= =A0





--
Ma= rk J. Reed <mar= kjreed@gmail.com>
--0000000000004d7d0f06160f0558--