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.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,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 E5011221E1 for ; Sun, 14 Apr 2024 15:25:08 +0200 (CEST) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1713101108; b=IiTzdVTnHAiYvVVXiWa04luxUdg3o2f0Js7VA9XieaiIY3ii/l/RV0IK5qZchej6kqVlIzpTPM dnfsC4cTS0TcnIQzmhq+aN+LbH+3AG8d4m0DXRAPOYWvTqqftZ2CMb+LK1uw3Td0QFPzcZvoGc ORaCmoN1M5rSLGixoRrZg6a/6Ic5LFTqmRXM1gL3fS3cAb0Qizb4rbLrjO4fjcSCeKXMFz1R0R 4wJc2zHlYxzngquetw0DuNPzig23l3VXVnPfYRyxPW0CHjKExTAEhKYb/h47X4Au4j08khqjKL C7apRyAoNfsH23o+NAJ4dqFXJ5yJxgkpfW3DkZIOS1OXUA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mta03.eastlink.ca) smtp.remote-ip=24.224.136.9; dmarc=none header.from=eastlink.ca; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1713101108; bh=3IW32CIYxw025DKhhoEptulVhbZQAJg3g4Wb6aiFDGE=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:From:References:To:Subject:MIME-Version:Date: Message-ID:Content-Type:DKIM-Signature; b=B4ic1/Q66i6nrZ9gHY4jDul5xQm21kZrLVT3EFLvO8vgpqseGx7yi13zpZ/MhhSu4xlmBQkX5t O1k2+2650Ym5W6SiAGfR3ex9+9Tzfxb/EbJ2sxmhDRwNXowk1CaVUcnfLBTggh+/s2evTK8ozs o6+R76JGhpifke4Q0/eiXAdtJhc+NcyYg1AyFtoPlBQR09jG6eCp7KAPTms3+n7LlCYFWTlDCd qA2aPu3/BAttYcst8ZJD+LUqwp4gfiSALEOaenpcwKYiL+ozRz7QSYxUdPWJBUPEGcVrHMSdQ0 sX+BxfI/x9gPz9S8EOVQSGh2LH5N8e27eNyunjZmSPLKFQ==; 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:In-reply-to:From:References:To: Subject:MIME-version:Date:Message-id:Content-type:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=8M5ud4ODKDieuKqky1yYvi4UOTG8NWtVqQFgkJtDuWY=; b=sHGX2iAgQRHcTu7xP0972E4T0H LH7NIs2P0gtAqQ1LUkCfQq76mCVkJce0KXPqgkT+4d/DidECqEm8OaIRYUMo+Wgd1p73KHHqh3/SW XLiHaEm3iZ/XeYyd2xzMpieKw3RZW1GT1JzKKI/9QDfH2aJmtIYiarJhJTyNI/RKkrXEuUWTKVRlg OocmQx9/4AJntdDr7PDd4CMeIcpB9md7GIUgD+p7WKxHKNC8q/1V+7xECXsYiOLy8k9kzw//WmBb5 NdoLlLvHlamKFzXPOUZZ6COXT+n71N8vkUqHVlJJUueqQa6MGP+OnlYOYuNjJUYeBjUuIFz5X6nzp n+vQya1g==; Received: by zero.zsh.org with local id 1rvzr0-000Ba4-L2; Sun, 14 Apr 2024 13:25:06 +0000 Authentication-Results: zsh.org; iprev=pass (mta03.eastlink.ca) smtp.remote-ip=24.224.136.9; dmarc=none header.from=eastlink.ca; arc=none Received: from mta03.eastlink.ca ([24.224.136.9]:46117) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rvzq9-000AsQ-H5; Sun, 14 Apr 2024 13:24:14 +0000 Received: from csp02.eastlink.ca ([71.7.199.167]) by mta03.eastlink.ca ([24.224.136.9]) with ESMTPS id <0SBX0EN2BP6NGE01@mta03.eastlink.ca> for zsh-users@zsh.org; Sun, 14 Apr 2024 10:24:12 -0300 (ADT) Received: from [192.168.0.11] (host-24-207-19-13.public.eastlink.ca [24.207.19.13]) by csp02.eastlink.ca ([71.7.199.167]) with ESMTPSA id vzq7rjJdw5Tsrvzq7rERNa (version=TLSv1_2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256); Sun, 14 Apr 2024 10:24:12 -0300 X-Authority-Analysis: v=2.4 cv=deIj3mXe c=1 sm=1 tr=0 ts=661bd8fc a=e7T7DzMKK1R988ZCg0wLyw==:117 a=e7T7DzMKK1R988ZCg0wLyw==:17 a=r77TgQKjGQsHNAKrUKIA:9 a=hOSwXcjBfJZYYSGdPmEA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=pGLkceISAAAA:8 a=8KdulLjfNH7U2L_G0CUA:9 a=bGJqql8Myb7txj-p:21 a=_W_S_7VecoQA:10 X-Vade-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudeiledgieeiucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecugfetuffvnffkpffmpdfqfgfvnecuuegrihhlohhuthemuceftddtnecunecujfgurheptgfkffggfgfuvfhfhfgjsegrtderredtvdejnecuhfhrohhmpeftrgihucetnhgurhgvfihsuceorhgrhigrnhgurhgvfihssegvrghsthhlihhnkhdrtggrqeenucggtffrrghtthgvrhhnpefhteethfevgeeuvdelgefgvdevudefueduffdvgfelvddvgfdtieegueeuleeifeenucfkphepvdegrddvtdejrdduledrudefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepvdegrddvtdejrdduledrudefpdhhvghloheplgduledvrdduieekrddtrdduudgnpdhmrghilhhfrhhomheprhgrhigrnhgurhgvfihssegvrghsthhlihhnkhdrtggrpdhnsggprhgtphhtthhopedvpdhrtghpthhtohepreerpdhrtghpthhtohepiihshhdquhhsvghrshesiihshhdrohhrghdpghgvthdqkghiphfrrghsshifugepthhruhgv X-Vade-Score: 0 X-Vade-State: 0 X-EL-AUTH: rayandrews@eastlink.ca Content-type: multipart/alternative; boundary="------------auw26IQIPAXtT6ekaGVXSE0o" Message-id: <4e9aa98c-9b5d-4e22-b7fc-8c50a9af9ada@eastlink.ca> Date: Sun, 14 Apr 2024 06:24:11 -0700 MIME-version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: triviality regarding $# counts To: zsh-users@zsh.org 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> Content-language: en-US From: Ray Andrews In-reply-to: X-Seq: 29818 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: This is a multi-part message in MIME format. --------------auw26IQIPAXtT6ekaGVXSE0o Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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. --------------auw26IQIPAXtT6ekaGVXSE0o Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

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. 



--------------auw26IQIPAXtT6ekaGVXSE0o--