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.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,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 31C6B21621 for ; Thu, 18 Jan 2024 23:35:04 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1705617304; b=darsbhf3m2z9uUcjQq0wDK4D6KVZjM2swhBSgvB8RcXCvUaBhQWrL2W6rI2W8vmSF23fG9vINx m3czFmchTYBCyaP0KSfV6ILCK/IQITGu74UnHjecTDqdWFMKjHxRiDWoqI6851ZqyIocc1JJsz i/F68w/RCMcL0BbW5asHLTwqR9iie7dUxDeDb3dGimCUZct6igHeQRMSbjFK07nYyyZGnXB9am m8S2ogCg2ocDILwCX3Off4DHcfYHX8x590wJc/GYFi6ZMrNpVGYO31HH9XvOJkfVWtEgWt6GYk Q8RJXFcI/dZvCYNcydEQQcr8OWkoBMJs0YOM2CLeGRbuRA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ej1-f49.google.com) smtp.remote-ip=209.85.218.49; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1705617304; bh=w+13KGO6TVMs6IPMIJRsNObS3R0wXwXMnMw3RaXsYxs=; 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:In-Reply-To:References:MIME-Version:DKIM-Signature:DKIM-Signature; b=FC+zwXKnLU0xiuQPfGBNhelWYu4+cT7WhoAZ82hFcXA8AqbwZXx2BF7r8Df7h5ySltBuBaSIoM TnrRPCUZRQTqu9F6TNyCLj3zpq+8eorK+cP+aPVD3D34xJBiss2QOFTB//DY5paGTu4iaI6Cim iqSmSUeu5wKRDMYw0Uef0QGqnQ39Kz8Tix022F+EuXxZ1TTrI5B+eTLeizkGOdL/Yta/WRrInp VDiFN/ofnusSnrQnbrJGTYPJFz6+0KPmgDTLAKKK3PTxFUznJqHFTx06DJiVB65NqwpHWAjL7N F5Qy4kaH3m/KG4A/mVcRrK9312yUMAc7zD/1VVhlVmKIFA==; 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:In-Reply-To:References: MIME-Version:Reply-To:Cc:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=b14zdAhHlbblE9ZuibpN1E1b6FqWlQ7D64B2vsiwnD8=; b=b9KE8mcgaY4W00Iq5aboRBQy+g an3Wswd3av6yBdcXyMFO7ChxX8eT1DB327y8z1YHnB1kHGjayhG4u49WG3iKXYHJJNaR4XhGKxtuI lo4oZQpcpIZjXbb7QvK0BRJAHL6Wo+ZH0MCBBfQ69bVLpXzXDDmBWxEaxeJQhRPct5LWG/BjjF9U/ IIUpjSwveie0vs/k9ESpGNEt5wPPGW1ld5mSScrq/Ys/bViMntYM8gXAwnkNbr2GvsNgQHvSCCOLw VK9lMJthJHJb38D8SdALtG/dUgrMbXTZp2I4utFgZr9S3nL0w3jGptxgE5aTLdMYkRw+6cO7JkBz8 EzPzYFZw==; Received: by zero.zsh.org with local id 1rQayU-0005JH-Rb; Thu, 18 Jan 2024 22:35:02 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ej1-f49.google.com) smtp.remote-ip=209.85.218.49; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ej1-f49.google.com ([209.85.218.49]:54506) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rQaxj-0004bd-Do; Thu, 18 Jan 2024 22:34:16 +0000 Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-a2bdc3a3c84so12116566b.0 for ; Thu, 18 Jan 2024 14:34:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20230601.gappssmtp.com; s=20230601; t=1705617254; x=1706222054; darn=zsh.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=b14zdAhHlbblE9ZuibpN1E1b6FqWlQ7D64B2vsiwnD8=; b=TnKJTvEAh9r4o73SppLAqcZRz292bR8greex5fnj5HOHR/FCoXR1u6lyw6bsx66TnR pyS/iFVicHFzkMMzR7to0EKEz/vaXhXVLk+2n85I2vG2dp90HesfPP9nwHEe1iJSQHon Z8aBeDn7CXFkPlmFIMhNvUX+f0AdUQEysQqxVE+53wVhlH4Ee1kIWk9VSZLXGyQP3ym6 nsGEbLGj4BU4SGRd4x4AFbpYVvFbJR3KKCRH2lnur5D1bel8B2UDfvbazR8wu5NaMU7N anjtprLdF5QWDtdSvmcK7WpFwlvploh5wBFPGx7+8BiaPfEcMLzeo/vh/oZHZHPob6u6 lF3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705617254; x=1706222054; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=b14zdAhHlbblE9ZuibpN1E1b6FqWlQ7D64B2vsiwnD8=; b=flnkT6Eh2aeeDmcV1uom8XjNeirdmTsyBV9/iR0RP5SDN4oiIZi28gtQCQaiwX/JyI pDUQXX3Nuu7kCOzRhlTYIX41Ro5i6OIlnlXQEArhewFCoh/3hAA7bcL4Q+lYvNxqjZxf s89hUROoi3T4djN2XUB3yFEr3FfKkt+6X/gOEkMRc5U8ZOX9SfXVWS2QNO/9NVbvydfx TxQARvias6eQdkRv1uq7Egd8zG0EYJ0PyRUJ0ABPYEqoVUAhzOK0cujyWehQZcv2jkxR XLmW8SyTIEoTSKSCZ76bJH0JjTfKRqO3+ufwvCago5I811EfHic6glw6YstHOrZ84fuR cI1w== X-Gm-Message-State: AOJu0Yw7idA63ZqWeoI6r9tgoMKSVEyOLgyVBjHrT7vcJzVy1rngdRs0 EG4WKWN4tpwMXt/76JGkBI+nOwqqtQCsZVkRYMTBuNFYGAoBeIJlSbVxtQOSsmgNWdmXSkTxv6q y1KxA2Dy3mIaS8swYJg6dEWROoyZzcOIfEHE2/nbn0gDdDZE= X-Google-Smtp-Source: AGHT+IE9bC/AmC3udonmYyVwfsK+gTcczWVL0vOgPge6wg6p0XhFiD4CI7rsi4MpssOprLG+NAd5ADDKJSMhLBZBzvM= X-Received: by 2002:a17:906:5946:b0:a28:e5eb:3f31 with SMTP id g6-20020a170906594600b00a28e5eb3f31mr808701ejr.80.1705617254521; Thu, 18 Jan 2024 14:34:14 -0800 (PST) MIME-Version: 1.0 References: <205735b2-11e1-4b5e-baa2-7418753f591f@eastlink.ca> <7b20b425-59b2-466d-a9aa-a2768d1d4633@app.fastmail.com> <4b475319-ef78-4d46-a62c-27c3b0af3ea4@eastlink.ca> <49702cd2-814c-4461-9819-cc2b85bd3ea2@eastlink.ca> In-Reply-To: <49702cd2-814c-4461-9819-cc2b85bd3ea2@eastlink.ca> From: Bart Schaefer Date: Thu, 18 Jan 2024 14:34:03 -0800 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: 29517 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 Sun, Jan 14, 2024 at 8:09=E2=80=AFPM Ray Andrews wrote: > > 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. There is an alternate (in zsh, it's the default in e.g. ksh) assignment syntax for associative arrays: asc=3D( [one]=3D1 [two]=3D2 [nil]=3D ) The "not clever" pairwise assignment is a concession to zsh's base practice of always passing expansions by value rather than by reference. That is, you can not do typeset -A asc=3D$otherasc because the defined expansion of $otherasc is an array of values, not an object reference that can be assigned in toto. > One might think that the order of assignment would be 'the order' by ine= vitability Associative arrays are maintained as hash tables for fast access. Expansion is in hash key order, and the internal hash keys are computed directly from the array key. Anything else requires performing a sort at expansion time, and/or (especially if order of assignment is to be preserved) storing extra data about the order (such as a linked list through the hash elements). Zsh opted to do neither of these on the premise that access to individual elements by key is far more frequent than access to the entire table.