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 60B002898C for ; Fri, 8 Mar 2024 19:30:59 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1709922659; b=C4R4cc+tEz7TlBZLwsZg+k3LymO/mnyMQAHv+VaftQKIXs01s/cI7upvw47TjqP/6usZWpIsSf Jn/husd6x1pQHsogrRNt2OHSSO9RbpetgC+MIpaEDJMrBC+EBFfdGZ+3k3rTO2y52euuRBzqVe ZllwUlNgl3CTU4Cxjj6JXZ1M6SpaOTjOtWdiVsDv4zsi4qfiUXJgc0zUm9PUrijsbde7+eHGK9 kvkK8Hj0OEulL2WSbW3GBmoAvHmb7/q8TqDbuhLJsBwun12XZWR+ZJXrk4IMD3BeubTYd4HxK+ DfvB+Bl0stI7qYOglCwApdeFtquVZEEqIITygYzpC0prPg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ej1-f54.google.com) smtp.remote-ip=209.85.218.54; 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=1709922659; bh=DlNFx+TSFU8dekbWcxuiQpFeG5QjdSUdPOvaHwp4QP0=; 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=cpZCsh2SpMqhn90SJnpaSuIIFN/SLEM16eft+SMjPptOq/0L2t1bdYQCM6keLADHWLHP2m8FOi cgJrcyL4CbgDRLcj3ohBUasmRCXG0qlniKxQKlNbMsNE7vKA5YrFGBMV3RNuX4lGoe0+WHTlAX dBDEs2GosXgFZ0fBwx8cb+DMGU3Fff6JTljlHvctcpPNizU4sw5f8I5KdQF9AiPLFycu1ZIV6Y j/vyvzJoI3mwXVP765R9M7utjYlRaRl7HwJYHXcTRBjeUsI1TY1c/hF+9DEahPFyk5doS/u/vC YRfmQ5JNeaxg/hlSE7kC0C0Wei4QPDxavZunGQoznLxJmw==; 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=2n2keal23+JQT8nt7BjZ8ElGA47nq2t94DfYJQgPLdQ=; b=BBKqY7lThNfbpUkpNmEIhDmd1e wDMXVw6YUkqDyAYMaDaixJVHwtAFKRMBN7LqpWFyypCNGJhM/dGn+9yoLVY+YXFofrpDGpkH/OXGG LkFgtfNw7ESq/Xs25vANF2AWnYpE+NLajT1DCVzj+6wPzjEQas5XHjDhRi6j8Nwr/rcM8nF2MlgTR A8D+dbcIWhV/LQzVYJx6Ifv9G0L8kpI1fm9wLPg3xZydT4deUGQIK2/H9mKW1LomAgYxNtR9zKHuw 2FHRod3Siza13cjmG2sOW4dZANWCZDpV/qcJlrdCClV4moxJ4VQ5l8XJwYnQTbx/Fmx8OtOrVmTLm EaC8DkrQ==; Received: by zero.zsh.org with local id 1riezg-0006T7-T6; Fri, 08 Mar 2024 18:30:56 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ej1-f54.google.com) smtp.remote-ip=209.85.218.54; 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-f54.google.com ([209.85.218.54]:47609) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1riez0-00067b-OG; Fri, 08 Mar 2024 18:30:16 +0000 Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a450bedffdfso328020066b.3 for ; Fri, 08 Mar 2024 10:30:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20230601.gappssmtp.com; s=20230601; t=1709922614; x=1710527414; 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=2n2keal23+JQT8nt7BjZ8ElGA47nq2t94DfYJQgPLdQ=; b=kgFGxcMmu53q36Jm/PdeZKQ58fdvCNY7BftfI35QW5LTGKfsQ/sx6e7wmeNRBTAR2S frKmWKZqqF472mJROgLHNHHFWC9atHpEGdj/8QahL/KlTff7s+tQ6wSHfaFa7grpOhGh Bpmx7we+QO4UNTUrABkA88SR4U0PqtT7Qc6PW9Kx5li3PrWw5DBVK3iQ8SzTfZpVXgDs XhiBJq+s7wt7Cafc3HCS9IUAL5xkMDrMwT/ltM1n44y3rJQ78EWe/AzMOs33nmHWDDLp yF9It276nVAp1NbgT8FX1bf7cuCLuGSPJcl49U2l0G3skKUNgakD/F5Bq2X//jvOwVvc glag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709922614; x=1710527414; 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=2n2keal23+JQT8nt7BjZ8ElGA47nq2t94DfYJQgPLdQ=; b=P1jfQHszx7Q4WJRE6j029bRxEP9sHV33hdo8lefwJrwbXyakv6GRF6mvH/I5zVW/w2 kjFyewpvQLjGzB6Kzy4bLJmpyBB3D32NjRTv0ZeCdkDOwMrliNPUHPutFq9xwpfOCHjB QfJ5WbjJwNhRpDwQI6ygvE2X7HJh2DFPjyeBN96eANb9pgnGUZTIKeOQuoADBDBPeaDj 2wpMMEwa2TLt4f4QSTtLPt2VRdB9qna78imtBs5EViqADTkCA4vlPKgd6AHEP2j+UXVo BtnMF6mle8eIhhHHqwsJGnC/XccWy6ClX1o+DOSCrVhudZ35DsNYO8xbhDRfukusdO+I pGGQ== X-Gm-Message-State: AOJu0Yzg71tALkpD9SIIp82FktkKuPV94jGCPhANE7uWqFe5xszCyrQU seXgjJ9UON1wD/V7URAYRWWs9jfdXDWi3+dOwkqvdNpIrTXth+CmecneHtqIbJ4waI/sbCXgW7F 1HNQycOZdj5GEIK4x9BkqvY+flNkel7VV99g+81z5r5+mN7nCoQ== X-Google-Smtp-Source: AGHT+IGLv0xTp/TjZky/9dQq+LBYtCWd/rtp2Wci+eKzEscJ1DDlCr8ERTbkTXocFitCdFN7HTNZa7ln/2D+ioPAzso= X-Received: by 2002:a17:907:a786:b0:a45:f39e:aad with SMTP id vx6-20020a170907a78600b00a45f39e0aadmr1878614ejc.1.1709922613674; Fri, 08 Mar 2024 10:30:13 -0800 (PST) MIME-Version: 1.0 References: <20240308132307.xvc3mh4uo67wvr4x@chazelas.org> In-Reply-To: <20240308132307.xvc3mh4uo67wvr4x@chazelas.org> From: Bart Schaefer Date: Fri, 8 Mar 2024 10:30:02 -0800 Message-ID: Subject: Re: namerefs to var[idx] To: Zsh hackers list Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 52714 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: On Fri, Mar 8, 2024 at 5:23=E2=80=AFAM Stephane Chazelas wrote: > > $ f() { typeset -nu v=3D$1; echo $v[1]; } > $ f 'a[2,3]' > f: no matches found: bc[1] Things are pretty tangled here: paramsubst() calls fetchvalue(). In ${v[1]} the entire reference is handled by fetchvalue(). In $v[1], the $v is handled by fetchvalue() and then the [1] is handled by paramsubst(). So it ends up being treated as $a[2,3][1], which produces the same error. I can't immediately think of any way to fix that without breaking something else ... ideally we'd make $a[2,3][1] work instead, but that's a pretty large change. In the assignment case ... > $ f() { typeset -nu v=3D$1; v[1]=3Dfoo; } ... the left side of the assignment is interpreted more like ${v[1]} than like $v[1], so everything "works." I guess one must remember that omitting the braces around subscript expansions has always been a shortcut rather than "the right way to do it". The braces are required for correct handling of namespaces, too. > $ a=3D12345 > $ f 'a[2,3]' > $ echo $a > 1foo45 > > In that one could expect the first character of the "23" > substring to be changed I say "more like" above because: % a[2,3][1]=3Db zsh: no matches found: a[2,3][1]=3Db % typeset 'a[2,3][1]'=3Dc zsh: not an identifier: a[2,3][1] So using a nameref that way is rather a back door around the check for identifiers. This is an interesting variation: % f() { typeset -n x=3D'v[2]'; typeset -nu v=3D$1; x=3Dfoo; typeset -p v x = } % f 'a[2,3]' typeset -un v=3D'afoo2,3]' typeset -n x=3D'v[2]' So chaining subscripted namerefs isn't really working, probably because of something similar to the paramsubst()/fetchvalue() division of labor just mentioned.