From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,NICE_REPLY_A,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 9515 invoked from network); 11 Dec 2022 20:52:53 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 11 Dec 2022 20:52:53 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1670791973; b=O0f2mj6e/N7gq73wS8n10Du9F//WVut0hXZ5EMF77o+N2IbPnXMOU4gYCFsUIGcQBS0AmzzVMI Z8RvZvErgZNB6RZXY6ERm4VrI21I/m+ws8ATcHAI2N/IpiNHIn6QN8szxx1tS+W+KrQjgOi9fw bMu592ntcaKojeqCRlCd8m0t9H5iHQynRc4dMWBMa7/QzduwgH0m7m1TT4SNo9fg9MTZjY/oKk GWYaaqgBgUuWiHmJqhO9GkdPuSoZRXLeyN39P3jqpBhsnfLbHGsxx6V5IGyCl3EmEkhiY3W3Bu Q6SdcF2yyIXJkBAfryL5daiUXE0kbxsOPzTdxX0DxYXXSA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mta04.eastlink.ca) smtp.remote-ip=24.224.136.10; 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=1670791973; bh=6EMawpgKuMhSsricXx8k/jbaNxb2CjY2cPLgTKcisB8=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:In-Reply-To:From: References:To:Subject:MIME-Version:Date:Message-ID:DKIM-Signature; b=rC9WwTR7c7IT1kN/yvGf26cgt4AjPEMtxMJ3MhViks5JEil+1pGFFxpVQ6rqN8rg1FrOm7PYmx 5qLFERQiJmyvxtv35SWn4zEu6Fc6fb0W+t0yF/a7yhQ+dPK3K7BDjRPteuwjTeUrJHa8zaG0oX uhCDKHr7nZGmQFIbovWUGO/wu2F2mtEQQN5dkweiP/5TRIuQNtTwrZm5zW5QF80br8mZBZ8xHP 5x+xsv734crlFGV68isoRyXAeCJMzpkDk2H+3m9tpUMNZzNjd6ZBY9m95L+HNIJIKrxKCHTESv PVEFrfzAJ212677R6i9MzI0x/mO0dD8FtD6Eubm/VSFhvg==; 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-transfer-encoding: Content-type:In-reply-to:From:References:To:Subject:MIME-version:Date: Message-id:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=dhJ5RTQFtmC2DXzfxZC5SXjv41MXqSxnMoDOOAYdQrw=; b=BI3/AKOsSQW7x1+m1aql73d1PZ gE48LO8YSG4XwPoiL1Ln5V7GZoGNkOlGQhhEUm7IPcLsXrWQb49mDPgEz9QoOac9G/fbki3HypNLF Ccax6JktJ01wB5uxjw5U6Iag3ZyDaYd/6YKqUhwfL9z+wdNIfGRA9/du0L2J/12YLvW2uuiIiThrZ f3FYjJJYpSTlbchwrrQtnCjEg9dWlOAJDJqmqAoWIztJs9dnYf6dHm4XbJg/op8NY3z34PTEQtU/v DHcs9kUFGHm6lNjtHxsIZRLXVWsoYmd5v3vDjQFhH2/sE1kFUCB2khGLlabGCt48ui4m5aJaeJLlK M5gKKB2w==; Received: by zero.zsh.org with local id 1p4TJb-000945-Kn; Sun, 11 Dec 2022 20:52:51 +0000 Authentication-Results: zsh.org; iprev=pass (mta04.eastlink.ca) smtp.remote-ip=24.224.136.10; dmarc=none header.from=eastlink.ca; arc=none Received: from mta04.eastlink.ca ([24.224.136.10]:55065) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) id 1p4TIl-0008Mh-7L; Sun, 11 Dec 2022 20:51:59 +0000 Received: from csp02.eastlink.ca ([71.7.199.167]) by mta04.eastlink.ca (Oracle Communications Messaging Server 8.0.2.2.20180531 64bit (built May 31 2018)) with ESMTPS id <0RMQ001SDV3RX2H0@mta04.eastlink.ca> for zsh-users@zsh.org; Sun, 11 Dec 2022 16:51:56 -0400 (AST) Received: from [192.168.0.4] ([24.207.18.108]) by Eastlink with ESMTPSA id 4TIhpz7XUeLAh4TIhpX24M; Sun, 11 Dec 2022 16:51:56 -0400 X-Authority-Analysis: v=2.4 cv=S7gfgqgP c=1 sm=1 tr=0 ts=639642ec a=xN66ZtSbq5jdJYpBp7G/jQ==:117 a=xN66ZtSbq5jdJYpBp7G/jQ==:17 a=IkcTkHD0fZMA:10 a=mjj_Rvs6krhJWc95WlUA:9 a=QEXdDO2ut3YA:10 X-Vade-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdeigddugeefucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecugfetuffvnffkpffmpdfqfgfvnecuuegrihhlohhuthemuceftddtnecunecujfgurhepkfffgggfuffvfhfhjggtgfesthekredttdefjeenucfhrhhomheptfgrhicutehnughrvgifshcuoehrrgihrghnughrvgifshesvggrshhtlhhinhhkrdgtrgeqnecuggftrfgrthhtvghrnhepiedtjeffvefgtdehgefgteekueeggeeitedutddvvdduteetffdvveelgfeukedunecukfhppedvgedrvddtjedrudekrddutdeknecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepvdegrddvtdejrddukedruddtkedphhgvlhhopegludelvddrudeikedrtddrgegnpdhmrghilhhfrhhomheprhgrhigrnhgurhgvfihssegvrghsthhlihhnkhdrtggrpdhnsggprhgtphhtthhopedvpdhrtghpthhtohepreerpdhrtghpthhtohepiihshhdquhhsvghrshesiihshhdrohhrghdpghgvthdqkghiphfrrghsshifugepthhruhgv X-Vade-Score: 0 X-Vade-State: 0 X-EL-AUTH: rayandrews@eastlink.ca Message-id: Date: Sun, 11 Dec 2022 12:51:55 -0800 MIME-version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: associative array questions Content-language: en-US To: zsh-users@zsh.org References: From: Ray Andrews In-reply-to: Content-type: text/plain; charset=UTF-8; format=flowed Content-transfer-encoding: 8bit X-Seq: 28518 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: On 2022-12-11 11:53, Bart Schaefer wrote: > There are no pointers to data structures in zsh. I know, I'm trying to fake it. > Parameter reference > is always by value. Even ${(P)other} returns a value, it's just the > value of the parameter whose name is in turn the value of $other. > Anything you do with the result of ${(P)other} acts on that value, not > on the indirectly-named parameter itself. So it seems.  I thought the (P) might force the issue. > There is one sort-of exception: The ${NAME=WORD} and related > assign-and-substitute operations. E.g., if you use > ${(P)other::=text}, then the parameter named by $other is assigned the > value "text". I say this is only sort-of an exception because if > $other names an array, you can only assign to the entire array, not to > individual subscripted fields. > > If you want to assign indirectly to a particular field (whether a > position in an ordinary array or a named element in an associative) > you have to store the entire subscript expression in $other, such as > other="aa[second]" > : ${(P)other::='tea for two'} That works.  I can intuit that parsing could be easier given the two stages, 'aa[second]' can only be interpreted one way. > Assignments are only parsed as such when there is an identifier > (string of nothing but alphanumerics or underscore, plus optional > subscript) to the left of the equal sign BEFORE any substitutions are > performed. Before?  Nuts I thought the substitutions always happened first. Obviously not.  So leave expansion complexities on the right hand side. > So this doesn't "look like" an assignment to the parser. set -x reports it as looking like nothing. > Lacking the outer ${...} enclosing the subscript, ${(P)aarray} expands > to all the values of the pointed-to associative array, and you get the > equivalent of > > "1" "two" "three blind mice"[second] Exactly.  I was trying to force it to accept it as an identifier. > You could also do (another thing that doesn't work in older zsh) > eval "${aarray}+=([second]='tea for two')" Of course I'm trying to avoid the eval entirely.  You've always advised against it. > Nope. It expands to a value, not a variable reference. Zsh doesn't > (yet) have what ksh calls "namerefs" ... block out everything you know > about pointers in C. Well, at least I knew I was sinning.  Purely curiosity tho, I have no real issue to solve.  So we still have functionality to steal from ksh, that's interesting. > Associative arrays are unordered hash tables. It might print "upside > down" or "inside out" depending on what keys are present. Ok, so no order at all.  That's quite understandable, it would be extra overhead for the shell to even think about it and there's no need. Thank you Sensei.