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.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, 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 A0D0A240C3 for ; Fri, 19 Jan 2024 14:46:49 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1705672009; b=Ohd6H96/YCaQpw8R449mHii2YBR3EK2XHih6LFQQmHZ6K4IFSUZl3719Bpla3nlJqD9G8+CLZn 0GxhSsxq/Ic25sVmscHA8LyppFfrRyVOWKps9nBLwF1Tsd/vsam2jbheMO4T+QgFOSNxJjkOxa IqAYaI2QpionVtIrxBgIrk+y1XB5L39rJOcicPpfJJFdZDZ9JxGOQFwQ3sleBXShx4fF5DfUMP K3UEJv5ACsZVHm3cVli7wUgMmqFOdpwpGvOVZsaN5xUxiix11muYgwtqRui31WOEW4ryaTiHiU T/MQCyetwLftwIT3sL/GnMluA0wB2vMiKWJ3lyoYpJFLOA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ed1-f53.google.com) smtp.remote-ip=209.85.208.53; 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=1705672009; bh=Us0ymxrxq6jxkzDDcAdFYhBvr+c88WD0DGLubemDJuA=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:To:Subject:Message-ID: Date:From:References:In-Reply-To:MIME-Version:DKIM-Signature:DKIM-Signature; b=c/oyDWWlUMgHbaoef+4pkudHDJAFYd8STE1scU5rXb5dGN3YNosGhnzFM8WFPnUliKiidp5gLV oVohOcnacv9tDPt6A5B/mV3ZK9RafDB7r7//yCs2sakeVcwL4XzDHKIZ618RPfs0w77/V2RR+k cMePOGjZiZ+EHycVlMFbKQMFKbGFbe5iEGEzj9gs3tYtRdULU33XwA6Em31YH3LlsdWtHm4J9g zA7RdWYh33e9/FT7N+Z7tIytocfyimytrt83TRDXkSOBcJMi4b3Wob/WCGie1fZsC1jlJ2ApCT S7PMpwq1TBZrQ3yBgb6YjFiw6nfKFbwpkWHlq7lDmsvftQ==; 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:To:Subject:Message-ID:Date:From:References:In-Reply-To: MIME-Version:Reply-To:Cc:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=Pz8v4cjiNdyifUSNG7ydAZKFrcXvJ24uQbZBdpXr3tY=; b=p2laetRoub2RJGx+mN2ZJWoIIK hlXfMTIt9NR6RxYvwCvCjNv2myJHi6Ahnuj25II2onsp3ARfjT1VP64WfrRMGnV7ySHU9pF49h22r RwDJZSkMwzX4iaZdpa7SQ/f8PHfpLvD/SBkzGBmiyGLGdiVKB4HgsmgTD+AXpe0GtzD14oFOajVkO s144PpNVWcuhREaGv9y2yjgaIOKo8LVnTDiN5PUaP3ThVkwqpj5lFkJ+eXzb5cNMPnHyo+cUUJuNu ErMDauRDSUk4pPywCp2S5e9hyWUUbGnrYBW5MSoiVDvUfMwbP8rCg4+kDDwPOHBfjCLISHLjI3oQu jZsEsKdQ==; Received: by zero.zsh.org with local id 1rQpCp-000Mc2-8x; Fri, 19 Jan 2024 13:46:47 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ed1-f53.google.com) smtp.remote-ip=209.85.208.53; dkim=pass header.d=gmail.com header.s=20230601 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-ed1-f53.google.com ([209.85.208.53]:46273) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rQpBt-000Lup-3e; Fri, 19 Jan 2024 13:45:51 +0000 Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-55a684acf92so581325a12.0 for ; Fri, 19 Jan 2024 05:45:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705671948; x=1706276748; darn=zsh.org; h=content-transfer-encoding:to:subject:message-id:date:from :references:in-reply-to:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Pz8v4cjiNdyifUSNG7ydAZKFrcXvJ24uQbZBdpXr3tY=; b=TZyKqJF9wTT1Kxwz/PA3ocLGfR/m9/xqzj98IKIXegAoloMkupTF0osacV3nXUnqhq dhzmZdqMTpE3baqrCBF+gr9I9UPTeWt6Xw3TqT95C68DSQG02H/X5bzio42Zo5Zfh9on ERPVJYbG/mrRflW+lYtv6DRqgrQE7sRFg6YXFm+OJZSOTtq0e2U8g5SyXDua+OR+suEG kWwP/4AzVDaOCO1ka0K+3QYCznP7FRW8wsVh2mORO6tCEcvRFgngOFsd8EcrQaadL1ZI JUBsCue/FDA7+idAK+CDZOkcUp+XNSp/fjgR31fHEFTEzswbBJqrDiTzwR5O+yGRaXPu KdnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705671948; x=1706276748; h=content-transfer-encoding:to:subject:message-id:date:from :references:in-reply-to:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Pz8v4cjiNdyifUSNG7ydAZKFrcXvJ24uQbZBdpXr3tY=; b=rJa7VhfcO73AURJYuus3OFBT2E/cZ5cEkS5Ra8O1O1KpmiQVA6hVulN95UEjIZI1RZ VgbS3RYYZ0Ux+eyYCNFk54cEw5iYNhgdTmg2GNwp4wQYs2e0cY59WIHbNuIjQiOBYAU9 5gJjIJaO8zE8FjyVD7fc7DJKIzmn05QH3aFw6hZAtpvuDUR9kSFnNvztpXeajhKPAVts MzZrnDkpx1YPTqrDyLPyCROKCnXlynCMBBiFAWCWbbqVo66zbH/sq9+tZgjKlxWsBklp O6RuzetNHhMxkFy0edtGPvVlqqEPu4aVtOa6Ekl3NYbLJKrHHnSxDox1Bh0pF3VuiQuj hfpw== X-Gm-Message-State: AOJu0Yx3zi7O0782GMiQp9qPVJt9H3YdJfHoFGYZXZNY9GqDaFn0NvBT irvIeQw3EQ2d3Nn+3yLLuxQPOwuJs6G6bJ3I3NBx8Jlv9oSBdLSSMLu7wp23+ZqcD75x3DLoAdD Y91+3hIrRMIikT/13sQOZTZKZpTdjoRA4 X-Google-Smtp-Source: AGHT+IECF/lzMbV6taRegSJLtFWIMkLanyjM+5YYiVIHU6+H5nEJqaSQRtZGUWUC47OC0cR/1d1xVxIAohQbAUYK3pM= X-Received: by 2002:aa7:c707:0:b0:55a:749f:8b44 with SMTP id i7-20020aa7c707000000b0055a749f8b44mr100873edq.21.1705671948452; Fri, 19 Jan 2024 05:45:48 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a05:7208:900e:b0:7c:1c56:f24 with HTTP; Fri, 19 Jan 2024 05:45:47 -0800 (PST) In-Reply-To: <20240119102755.5ma5psbccsuo5ohj@chazelas.org> References: <7b20b425-59b2-466d-a9aa-a2768d1d4633@app.fastmail.com> <4b475319-ef78-4d46-a62c-27c3b0af3ea4@eastlink.ca> <49702cd2-814c-4461-9819-cc2b85bd3ea2@eastlink.ca> <50941e8e-86e2-4e89-8644-c863f846e805@eastlink.ca> <20240119102755.5ma5psbccsuo5ohj@chazelas.org> From: Mikael Magnusson Date: Fri, 19 Jan 2024 14:45:47 +0100 Message-ID: Subject: Re: Empty element elision and associative arrays (was Re: Slurping a file) To: zsh-users@zsh.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 29522 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 1/19/24, Stephane Chazelas wrote: > 2024-01-18 18:58:41 -0800, Ray Andrews: >> >> On 2024-01-18 18:46, Bart Schaefer wrote: >> > On Thu, Jan 18, 2024 at 3:08=E2=80=AFPM Ray Andrews >> > wrote: >> > > How hard would it be to get the first hash 'right'? >> > That's not how hash tables work. >> >> I have no idea how they work which is why my comments have little value. >> If >> ksh can do it then it can be done, but as I said, it simply might not be >> worth the effort and I'm in no position to judge the matter. I wish I'd >> gotten that far in C, I'd heard of hash tables but never coded one. But >> I >> did note in that code previous that the order seemed not to change. >> Nevermind. > > As said before, in "${!hash[@]}", ksh93 orders the keys > lexically, not in the order they were inserted in the hash > table. It doesn't record that order either. > > If you want to do the same in zsh, use the o parameter expansion > flag to order the keys. See also n to order numerically: Unfortunately, combining o with kv doesn't work as one might hope: % typeset -A foo; foo=3D(a b c d e f g h 1 2 3 4 i 5 j 6 7 k 8 l) % printf '%s =3D %s\n' ${(kv)foo} 3 =3D 4 g =3D h i =3D 5 7 =3D k j =3D 6 8 =3D l a =3D b c =3D d 1 =3D 2 e =3D f % printf '%s =3D %s\n' ${(okv)foo} 1 =3D 2 3 =3D 4 5 =3D 6 7 =3D 8 a =3D b c =3D d e =3D f g =3D h i =3D j k =3D l I guess this is actually a bug since the manual states: v Used with k, substitute (as two consecutive words) both the key and the value of each associative array element. Used with subscripts, force values to be substituted even if the subscript form refers to indices or keys. --=20 Mikael Magnusson