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.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 31741 invoked from network); 18 Dec 2022 03:46:37 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 18 Dec 2022 03:46:37 -0000 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:Subject:Cc:To:From:Date:References:In-Reply-To:Message-Id: Mime-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=1ki8ml8RCyNmjPtyJnkERD05QzRg54JFS03U62UCn1U=; b=c1QCHj+5O1gkFdE9h/JIp4pKal RBsM1rPKQPMqb1pfRHLlPnBpyA0BLNk5q1QMjKvTLK5jmKFgZYMdIBGBMDw0prOwhih/giajENMJV wkBJuQk+NSjJ4gOoi7JL6Bog/nrtuKffU8F+hkHAk2+9hOUWQV1JeOUfkaCa3mBlYAG7JRnAPVyjP eAfUecd9OjsepsXcgsAmize0EXk4Oc9SX+LZZz7IXJotrIqx/+Qt+qcGdmLFB5K8QBjDrQoD9e6H3 4YaSudVF9gFkmstiwXoO1mDSrMfwDmp7U0n1f4ufZUw1nTUFfyrq8hqbMkiGmdxdGflc3kd5F1JQ6 5CzptSJQ==; Received: by zero.zsh.org with local id 1p6kdH-000POu-7i; Sun, 18 Dec 2022 03:46:35 +0000 Received: by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1p6kcI-000OiF-Ex; Sun, 18 Dec 2022 03:45:34 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailauth.nyi.internal (Postfix) with ESMTP id 6257427C0054; Sat, 17 Dec 2022 22:45:32 -0500 (EST) Received: from imap48 ([10.202.2.98]) by compute1.internal (MEProxy); Sat, 17 Dec 2022 22:45:32 -0500 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgedtgdeitdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvvefutgfgsehtqhertderreejnecuhfhrohhmpefnrgif rhgvnhgtvgcugggvlhojiihquhgviicuoehlrghrrhihvhesiihshhdrohhrgheqnecugg ftrfgrthhtvghrnhepheegieduieegvddvffdvgeefuddugfetvdettddtfedutdejvefg jefgveethedunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh homheplhgrrhhrhihvodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdduudeh udekjeejtdegqdduudelvdejfeekhedqlhgrrhhrhihvpeepiihshhdrohhrghesfhgrsh htmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: iaa214773:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 0645E31A0063; Sat, 17 Dec 2022 22:45:31 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.7.0-alpha0-1185-g841157300a-fm-20221208.002-g84115730 Mime-Version: 1.0 Message-Id: <3b9f0d96-8ba4-4196-b9ba-f6731f60ce49@app.fastmail.com> In-Reply-To: <93583301-dbe4-673e-f8b0-b515d1e97c1d@eastlink.ca> References: <46161d8a-c177-4134-836e-592e5c048887@app.fastmail.com> <902fb047-3435-89a3-e7ea-74e74075c2c6@eastlink.ca> <09d09690-08c8-4499-9011-9c45d7676f52@app.fastmail.com> <81952d4b-3ead-f912-f987-fe9a37dbd256@eastlink.ca> <27c7320e-7677-1268-3bf9-59939aad067e@eastlink.ca> <2c606231-ae9c-a7cc-8e35-e018ccead14e@eastlink.ca> <7a12a4c0-d423-4538-a194-18e9cf932fe9@app.fastmail.com> <93583301-dbe4-673e-f8b0-b515d1e97c1d@eastlink.ca> Date: Sat, 17 Dec 2022 22:44:18 -0500 From: =?UTF-8?Q?Lawrence_Vel=C3=A1zquez?= To: "Ray Andrews" Cc: zsh-users@zsh.org Subject: Re: uninvited members of associative array Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Seq: 28587 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 Sat, Dec 17, 2022, at 7:15 PM, Ray Andrews wrote: > On 2022-12-17 14:10, Bart Schaefer wrote: >> The input doesn't have a type. It's the result of a substitution, so >> it's just a series of separate words. Where the words came from is >> not remembered. Consider: > I suppose it could be looked at that way It could be looked at that way because that is the way it is. > OTOH it could be that the type > is referenced.=C2=A0 After all the type *is* recorded.=C2=A0 typeset -= p doesn't > just cough up the contents, it knows that an AA should display > differently than a normal array.=C2=A0 Since the type information is t= here, > there's no reason why it might not be referred to. Parameter substitutions do not communicate variable attributes, nor should they. A core design tenet of Bourne-adjacent shells is that, once the dust settles, using a substitution is equivalent to using the substituted values directly. Thus the following sets of commands work identically in the end: % typeset -A arr1 % arr1[a]=3D1 % arr1[b]=3D % arr1[c]=3D3 % set -A arr2 "${(@kv)arr1}" % typeset -p arr2 typeset -a arr2=3D( a 1 b '' c 3 ) % unset arr2 % set -A arr2 a 1 b '' c 3 % typeset -p arr2 typeset -a arr2=3D( a 1 b '' c 3 ) Your proposal would make a hash of this, introducing special cases that are incoherent and work differently for no good reason. It would also likely require "set" to be reimplemented as a keyword, which would be ridiculous. >> set -A thing new1 new2 "${(@kv)whatever}" new3 new4 >> >> What "type" is that? set -A IN "${(@Pkv)${1}}" # Copy the array to IN= , the working copy. >> > Not fair.=C2=A0 In that case 'thing' is not assigned any type, so it's > defaulting to a normal array is unavoidable.=C2=A0=C2=A0 But if I do: > > set -A IN "${(@Pkv)${1}}" > > .. and $1 names an array that typedef knows is an AA, then it wouldn't > be very much work for IN to be matched with that type. So the variable should only be created as an associative array if all the "set" arguments are produced by a single parameter expansion of another associative array? That's a very limited use case. > As I mentioned, my > case would rely on the precedent that that's the way it is with integer > promotion. I assume you're thinking about what happens here: % var=3D(a b c) % typeset -p var typeset -a var=3D( a b c ) % ((var =3D 1)) % typeset -p var typeset -i var=3D1 Arithmetic contexts are their own little universe. You can't really use them as a comparison point here. > Well it's simple and hopefully failsafe, but I still=C2=A0 can't help = but > thinking that if typedef knows the type of the input then the type of > the output could be assigned as well as the values. Should the following "set" command automatically create "out" as an associative array? After all, all its arguments come from a single parameter expansion of an existing associative array, just like your other examples. % typeset -A in=3D(a 121 b 121 c 23) % set -A out "$in" zsh: bad set of key/value pairs for associative array Hm. Okay, only if the expansion produces separate words. % set -A out "${(@)in}" zsh: bad set of key/value pairs for associative array Okay, only if it asks for both keys and values. % set -A out "${(@kvu)in}" zsh: bad set of key/value pairs for associative array Okay, only if it actually makes use of all the keys and values. % set -A out "${(@kvs:2:)in}" zsh: bad set of key/value pairs for associative array Okay, only if it doesn't modify the keys and values. % set -A out "${(@kvo)in}" % typeset -p out typeset -A out=3D( [121]=3D121 [23]=3Da [b]=3Dc ) Yay! It ... works? I'll stop here. Your desired behavior would have be applied so narrowly as to be essentially useless -- and certainly not worth the added complexity. > Daniel: > >> Could someone please clarify this in the manual?=20 > > Thanks. It makes me feel less stupid when someone agrees with me that=20 > the manual isn't as clear as it could be. No one actually thinks that the manual is perfectly clear. The disagreement is with your notion that the manual should be more verbose and have more of a tutorial vibe, when it is a reference and should be treated as such. > The manual was written by=20 > someone too intelligent for the job -- no empathy for the less gifted. Your learned helplessness is becoming tiresome. --=20 vq