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.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 19748 invoked from network); 3 Jul 2022 03:42:59 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 3 Jul 2022 03:42:59 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1656819779; b=nvXlmkbedzMeAVoH/mJaomx1wNAla/XfUz64NVuYLVvkmtqIQ/kt02ucn3SJOZvJtjmlJbeWWI TEib3RIEmKN4PZgTStb4suk7exlF3JrSn9LMm+Qjp2wAtBXAa3QpZjaunhCE9oF2KLkEnVIHDT cuCDHjYhgLRt3JZgjY+FLdbpPwar1poWNZltxLAn9W6dtGJkri4nPAcYrY5ysIxGhTyIB+OG3t LZrTg3e7RfvXvSGNu2V44PvRrdNZO2NHdzf9kekE2ffCJn3AdUZGerZjJTurDfMq5kLFK+Uii4 7mcGq2qGxuKuANLfcHBoUtwTrlSc5N0Vv94EgSnVGdrvTA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ej1-f44.google.com) smtp.remote-ip=209.85.218.44; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 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=1656819779; bh=+J3lX84Rb+yoDzImgote4qlGihDk0vpY/ImYKrPWq1U=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=V6r78D9+gyUq1g5haqH7cQa4SV9RoAfMR7YBe8r7fpB5Giu5rslJIqurWSTfyUTrIEFjKaor44 IKgYhWr1tWpB0a0SE5nb5nmQ5D0Whnjd5bF+AuQuIeE8mPVI7curwk4ilXitttYKYYKTqO4kL8 ILcjZFrtfh4BuCp3l/pDxX4UX0fsDNEssRzlVsf/A9mRqgzqnVmdR+USfy50A9ineF/ueqxIUZ V0g5hBAubZuxqKxGKlpXnqtQ/T2/7ueMZUbnOK9Ymx+lIdZjaPSyCvbsobTaCx90nwy4GoJ0HI bz0c9XbROWqzsqm0EooFI98hGPpJwnSF+kjOsceO2kPc6w==; 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-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=dHRFGvnvVvtZgOBGTcc1rahSg0ZplwxpKFTLfnobbJQ=; b=GVkPps6iX3KbLHNmFMEXMJSkG6 rUWHBYme9JJPo20UkQkm6UPMqZpG9bWbKKkYVq5Fao4BuIDL3Csd1IyPuX4mktSB0amD0/eBD0pFa p9tkAdbVR4XcHXcm2YPVEvptKfjIAUn9p+fyzIhqeraEIcO7t6YNUiXoG/fb56oq8B28d7spdUUDS X4Ke1Qz9WHVMUzZAmkV8wQ45LJOJVMHHFAN6qkZnae8h+leLUn82oEnUjyj1mvjXngoQ5KMraBbwd Sfz9rXkvC7wp2eapHb/X7CN7TNyuEzNTf7Cn52a93k6V4JKj6dcG7l7D+4jKFRHD1nY7RAf0dffJ5 MHe98UUw==; Received: from authenticated user by zero.zsh.org with local id 1o7qVf-000CpT-2n; Sun, 03 Jul 2022 03:42:59 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ej1-f44.google.com) smtp.remote-ip=209.85.218.44; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ej1-f44.google.com ([209.85.218.44]:35800) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1o7qUg-000C89-L5; Sun, 03 Jul 2022 03:41:59 +0000 Received: by mail-ej1-f44.google.com with SMTP id pk21so11028316ejb.2 for ; Sat, 02 Jul 2022 20:41:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=dHRFGvnvVvtZgOBGTcc1rahSg0ZplwxpKFTLfnobbJQ=; b=swU2ah+qCEzIRuZz1dj7wFcyCRXa219nw2D1XbSrXONP1N3lTLYSXlN6WzYpjVDESm lNlFrIC8389/xP+hUW9hCnMhzfjDu5lfz+QAERWSwzwxBJdpRdZzUWAew7V4aiURXhAf rR1VnlC4VlgC0oRY31+EDrXn0edSwv4QWrR+XgZy7k+lYHclZCrFUVa68S5jcFZGhy+4 k3NtV4XD8Pc2Sa3fD0cVZXsNlIdF9DXxdNReh+iQlcigt6KVJF0aqUlzoZpWxZvBhTPc ssTSzd0fcCNECZyVHDGRRJCnAw4huvnwuHRGLdYKVi0mT8Q4VCJ8gd9U94CMufSYt5AY hHBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=dHRFGvnvVvtZgOBGTcc1rahSg0ZplwxpKFTLfnobbJQ=; b=xUZVY9TSWq7mfSqcmXmRjZ9r8dkD7lYfQgdurLl+eA2cv39qDykndNmnfQmV8SHSO2 IE5Q0H0Wu0P3k1sPwC9lTpmD5P/smr1rMq1hIlpOwHUXd98hTvMcF69Sk5GAcV8f5xda J6qUYz8YPj8fEo4UbXX+nReP7vaVqq3psjDt55vF5XLHciXIkDub7GZn63XR00bRS68k eDgnL+M82m2wArar7t3zg8Vw33E+jnWlrfrflhfK9aDLM8B9AYEq41OFQ5BUwb7QGZ2Y zx9YhfHk/sOW+K39Iob/+AgRK6jDUf9MQTc5qURM3Z1KxzP7lSp/YOlxUmM+/MnW8cqd cuEA== X-Gm-Message-State: AJIora/j1qPrM8SdSCxKK3paHBAc7M7Vqf54KNo802wBSy+rVPmquwnq 1ifQuXT0EGk+fzm/Bk0QAXWsasn1eUL23leTK3nw2OT6k4BHwQ== X-Google-Smtp-Source: AGRyM1vUBML0A2nxNxLi5xYJZdFI08weQT+wf3AFeRq639VECZdCO5Lzie6Pdq0nlOfHMtknnTQFpyPEJTe+/Y3lulU= X-Received: by 2002:a17:907:7627:b0:72a:9098:e4d3 with SMTP id jy7-20020a170907762700b0072a9098e4d3mr9560592ejc.389.1656819718119; Sat, 02 Jul 2022 20:41:58 -0700 (PDT) MIME-Version: 1.0 References: <11ca04c9-1503-4cd2-a44b-635dc53e43a8@www.fastmail.com> In-Reply-To: From: Bart Schaefer Date: Sat, 2 Jul 2022 20:41:46 -0700 Message-ID: Subject: Re: indirect array element assignment? To: Anthony Heading Cc: Zsh Users Content-Type: text/plain; charset="UTF-8" X-Seq: 27863 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, Jul 2, 2022 at 7:28 PM Anthony Heading wrote: > > On Sat, Jul 2, 2022, at 2:13 PM, Bart Schaefer wrote: > > It's not that it doesn't support subscripting, it's that it doesn't > > support parameter expansions of any kind on the left: > > > > % echo ${${grape}::=raisin} > > zsh: not an identifier: > > Ah, that makes sense. Though hmm... there's some lhs expansion, no? > ${grape[$#grape]::=raisin} for example. Subscripting does expansion inside the [ ], but that's not the same context as ${${...}}. > Is it a necessary error by design? ... for lhs ::= I wonder > why ${${X}::=...} couldn't have well-defined natural meaning. For that to work, ${${X}} would have to mean the same as ${(P)X}. As a general rule nested expansions are processed innermost-leftmost, and substitute rvalues rather than lvalues. The (P) is what forces the current level of expansion to turn into an lvalue, but that doesn't apply to either the surrounding or the surrounded levels. So ${(P)${X}::=thing} actually does work as long as ${X} returns a valid identifier that can be treated as an lvalue. Without the (P) it remains an rvalue and you get the "not an identifier" error. (I'm glossing over a lot of what actually goes on underneath here, but if you're familiar with the concepts of lvalues and rvalues this is a pretty good way to think about it.) That does in fact mean that this works too, now that I think of it: ${(P)${:-${v}[2]}::=mango} > > There really isn't a good solution if you're trying to do array > > slices, i.e., a parenthesized list on the right of the "=". > > You're referring to the typeset style solution here, maybe? Yes. > Your later solution seems to work great for all sorts of array splicing. Sure, but you also have to do your own array splitting, as e.g. ${(AP)=v::=apple banana carrot}, if attempting to assign a plain list of words.