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=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE, MAILING_LIST_MULTI,T_SCC_BODY_TEXT_LINE 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 D27192A64B for ; Mon, 15 Jan 2024 05:10:20 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1705291820; b=mAVlR0xoz7duBV/VoES+stY34BZdb9j+IUHkDsxuiFkHHdva5dDR9H+W76sw1KbST7ehjRubbJ pzV/IDc+kKQNGvIVC3/HMB3xmaHBjOMVah3IlkQKJRSvSms1Kc48lb4u3e9kWb2/LgjyX5zxR6 LmiQJZvA3y2ld7ZB6t3fV8rgH4qjpRrZWa9FR8gL3rLgC4Hlp9UQj06te+jHteg1lw0b6uex+a o/6kg7duqGF72Gzz88QzuOafl5M+6fLQ/M4OxC2PgB98WSHTOIWDnTdOQSJ1vbAibMWmh8uhRm VBii6tP5NTpm0cJA2jjV5BJHBwtUFtL0/UfMzr7Jn70QOw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mta02.eastlink.ca) smtp.remote-ip=24.224.136.13; 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=1705291820; bh=nIa6tfUpDoZFhKGsQoa6Nce378953Y0lzBmah+bFb8M=; 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=KZQhu1Qixs//xzw/BTT+Hp6RvqiLTAVZvbUDjcURqlQUJ8VWaJjJVyh9vV5moWOirbrjVzVzi9 wWabYaL+S2B9nKQtmsfzmPkgPqjqPCg1pla4/1hruKlXdxzKd77wZJ1bshV4aeakpkrKtT+YFy NZgWZ8/XDQUb7iygexC0oQuIiMvfl5/CvFb7zYmLg2cjlp5sSsgzX+kFe+jIPykFjFkJtPQfc/ m30tXxEXu4Et+RuynjCiWA/SqizG57dQLD1WSuawnd5G2YBedWDF8qjDHvrUuzHYMrFOulniJx vTQxGZ9rs1i7mxblN3+FX/A7ycgpVCFiyzBRzGmcY2Qb0Q==; 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=PfhYM+dlrdBmaZBIp4lsybGpnAJdqnM3BYAMgZKCtAs=; b=YppsQug9Hodj6D6LacI/OMXK6n PEwRhPp6xF25ut37jfhd45GqvfInnNAjrp1P1hELEtyVXVrm7ZtT2H93u1h2tkYVElYF5EO9fOqDS nDSadU+pERx/0mcrGV1kHx2OxwzBWaroH1SlOf5ZSNhtXJMmnULjMnA4XyK4a+9oqMByp4jBiFb2c hM00Dpd2SmkL4mOZlQfDQastmCHKSZMmZv8h2jswu3y1DGQIqnDmsTwKTQRHUYRIdzM9EBS84S2xI NVRamwGUAmsNTc9+I4KZlAUX/siLLFOswixCMT9a7jA4pOAHVb0PF5DoWwddQaVTW2/z6Q1zSzQKm 38ixJEEQ==; Received: by zero.zsh.org with local id 1rPEIl-000BNg-GV; Mon, 15 Jan 2024 04:10:19 +0000 Authentication-Results: zsh.org; iprev=pass (mta02.eastlink.ca) smtp.remote-ip=24.224.136.13; dmarc=none header.from=eastlink.ca; arc=none Received: from mta02.eastlink.ca ([24.224.136.13]:50321) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rPEHv-000Aez-UR; Mon, 15 Jan 2024 04:09:29 +0000 Received: from csp01.eastlink.ca ([71.7.199.166]) by mta02.eastlink.ca ([24.224.136.13]) with ESMTPS id <0S7A0E5FJBGCHB60@mta02.eastlink.ca> for zsh-users@zsh.org; Mon, 15 Jan 2024 00:09:26 -0400 (AST) Received: from [192.168.0.11] (host-24-207-19-13.public.eastlink.ca [24.207.19.13]) by csp01.eastlink.ca ([71.7.199.166]) with ESMTPSA id PEHtrzPBtAItUPEHurEYRz (version=TLSv1_2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256); Mon, 15 Jan 2024 00:09:26 -0400 X-Authority-Analysis: v=2.4 cv=NJYTuW2g c=1 sm=1 tr=0 ts=65a4aff6 a=e7T7DzMKK1R988ZCg0wLyw==:117 a=e7T7DzMKK1R988ZCg0wLyw==:17 a=r77TgQKjGQsHNAKrUKIA:9 a=gir0-LH0AAAA:8 a=fhLUTfMD1_oZWcV6QUgA:9 a=QEXdDO2ut3YA:10 a=pGLkceISAAAA:8 a=HFOkTaeDOGNULQiU1h0A:9 a=Kr67RPkRX1h_bI18:21 a=_W_S_7VecoQA:10 a=lqcHg5cX4UMA:10 a=aLewGyoHDmJ4ULJHWpSz:22 X-Vade-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdejtddgieejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecugfetuffvnffkpffmpdfqfgfvnecuuegrihhlohhuthemuceftddtnecunecujfgurheptgfkffggfgfuvfhfhfgjsegrtderredtvdejnecuhfhrohhmpeftrgihucetnhgurhgvfihsuceorhgrhigrnhgurhgvfihssegvrghsthhlihhnkhdrtggrqeenucggtffrrghtthgvrhhnpefhteethfevgeeuvdelgefgvdevudefueduffdvgfelvddvgfdtieegueeuleeifeenucfkphepvdegrddvtdejrdduledrudefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepvdegrddvtdejrdduledrudefpdhhvghloheplgduledvrdduieekrddtrdduudgnpdhmrghilhhfrhhomheprhgrhigrnhgurhgvfihssegvrghsthhlihhnkhdrtggrpdhnsggprhgtphhtthhopedvpdhrtghpthhtohepreerpdhrtghpthhtohepiihshhdquhhsvghrshesiihshhdrohhrghdpghgvthdqkghiphfrrghsshifugepthhruhgv X-Vade-Score: 0 X-Vade-State: 0 X-EL-AUTH: rayandrews@eastlink.ca Content-type: multipart/alternative; boundary="------------BiQSzJ03rRVVJOChfjfvD1t0" Message-id: <49702cd2-814c-4461-9819-cc2b85bd3ea2@eastlink.ca> Date: Sun, 14 Jan 2024 20:09:25 -0800 MIME-version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Empty element elision and associative arrays (was Re: Slurping a file) Content-language: en-US To: zsh-users@zsh.org References: <205735b2-11e1-4b5e-baa2-7418753f591f@eastlink.ca> <7b20b425-59b2-466d-a9aa-a2768d1d4633@app.fastmail.com> <4b475319-ef78-4d46-a62c-27c3b0af3ea4@eastlink.ca> From: Ray Andrews In-reply-to: X-Seq: 29482 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. --------------BiQSzJ03rRVVJOChfjfvD1t0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2024-01-14 16:55, Bart Schaefer wrote: > On Sun, Jan 14, 2024 at 4:03 PM Ray Andrews wrote: > When assigning to an associative array ... > > % typeset -A asc=( $something ) > > ... the expansion of $something has to yield an even number of > "words", yes. But remember the previous lesson about those outer > parens -- they only mean that the thing to the left is an array, they > don't matter to what's inside those parens. So if $something is an > array with empty elements, those elements are going to be elided, > which might leave you with an odd number of words and break the > assignment -- or possibly worse, turn some values into keys and some > keys into values. Exactly as I understand it.  A arrays are 'not very clever' -- they don't try to protect you from yourself, there's no internal place holding for a missing value, and as you say things must be kept to pairs. > (output may vary because associative arrays are not ordered). I've noticed that.  One  might think that the order of assignment would be 'the order' by inevitability, but that seems not to be the case.  I don't understand how it could be otherwise but nevermind. > Returning to the original example, that means if you're copying one > associative array to another, you need to copy both the keys and the > values, and quote it: > > % typeset -A asc=( "${(@kv)otherasc}" ) You said something the other day that was important: the parens do not say 'I am an array' they say 'turn me into an array'  it's one of those things that must be clear. Yeah, I'm getting somewhat competent with A's.  They're not very forgiving but the rules aren't that hard to remember. --------------BiQSzJ03rRVVJOChfjfvD1t0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit


On 2024-01-14 16:55, Bart Schaefer wrote:
On Sun, Jan 14, 2024 at 4:03 PM Ray Andrews <rayandrews@eastlink.ca> wrote:
When assigning to an associative array ...

% typeset -A asc=( $something )

... the expansion of $something has to yield an even number of
"words", yes.  But remember the previous lesson about those outer
parens -- they only mean that the thing to the left is an array, they
don't matter to what's inside those parens.  So if $something is an
array with empty elements, those elements are going to be elided,
which might leave you with an odd number of words and break the
assignment -- or possibly worse, turn some values into keys and some
keys into values.

Exactly as I understand it.  A arrays are 'not very clever' -- they don't try to protect you from yourself, there's no internal place holding for a missing value, and as you say things must be kept to pairs. 

(output may vary because associative arrays are not ordered).
I've noticed that.  One  might think that the order of assignment would be 'the order' by inevitability, but that seems not to be the case.  I don't understand how it could be otherwise but nevermind.
Returning to the original example, that means if  you're copying one
associative array to another, you need to copy both the keys and the
values, and quote it:

% typeset -A asc=( "${(@kv)otherasc}" )

You said something the other day that was important: the parens do not say 'I am an array' they say 'turn me into an array'  it's one of those things that must be clear. 

Yeah, I'm getting somewhat competent with A's.  They're not very forgiving but the rules aren't that hard to remember. 


--------------BiQSzJ03rRVVJOChfjfvD1t0--