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 E20B825569 for ; Sun, 3 Mar 2024 20:04:36 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1709492676; b=r4jqt36d+C7twMFJDOcRbzkQM6VXqlXbpzCm6dWguDAsVMQ297dfP3VipqnJ+WpX2Bq0hoiXu1 jVEMXn0FyK+HwtE4aZsv5wwcwGJ/fxLvJwM+47uOSmCOJMcPbF+ldeJUnJZhsdfqoOuJt+s5oW rP43r3uTc8b7sbj1yn8dzL9DucFnw/Ym9NVw2lMZFKzWOxno+xxnl/iUgGahfpwKX5YT1Miwke kkMkimidqDCges4jQp+arQQ2JlnCA+5UKDf9isXoxpdCzyVeMfg3zyE71RFWyqK1vfqjemkCNG pA1MvYndbli41271OCFSx0+tPsP/Anul2rtEU2katw1f9w==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ej1-f51.google.com) smtp.remote-ip=209.85.218.51; 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=1709492676; bh=1ID3+2ojMbmTpBw4Dsagz5UckQaeOm4XgdQyIR9Nxr8=; 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=Z+8INoo1L9FUoS7Rn2N2grwMAxoiAJMkS3Msx1Ogn2vkzAHH1X8WnuCH5D4FiuirCXJxlH/BL6 rqRBrUy1q9fGlpmz/7BGhhO2Cs4eczSnpA5vAptfVbKSQ+oBgrcIQ1c7mWr2/JR/SbLDGsg27H gWo0v6aMUk3D2FZR3L1tJUN72bfnW4VULkWxLPAAYHE0Snz1iIroibxBb245e443pZVPXXHZMf 0p0HiJleP4lf6N86zEjBfd1ChhabCnSevrlqPKWjpCDLaulqDJn0fm9S8qpylWMcJ6WbOX9+r7 08SouWQ/qYYB2FFvLeuC5LBpVD7XIignIDZgfyl6Gxqp8A==; 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=+Ucw2Qrm1j9mBky82Z26gMPKDjXOpjSJs6scAp7kTi4=; b=YPYemGS7VZP4x6OC2L2Eez01xq MO/4XIlBHObpO09TMsP+DVgdgjrZmL0Bn3S0K4D6qOrM2DgpeDpJ/fK6VZIVb58M0qMaWwb5goO/C XbTaycNkgl5XbUd3us58tB/USLk+UfSR63LXlmYahYe8wNUXf876kAzUgFMG3yLzeaKyCW9FeS510 dD1pSRg79H/AcFOC+yuz/tt+/TukjNcOqPyX7+sKEVbCxZbn3oZcRXyfSSnlFdyX5Gm5fQpq6VgxX 9H64cJv7kNV14FUazlr5b4xBHbPQXqDaw3E5jvUYzQyHXwy36j7s6cQFaiBKtOSLHAiH/PEmtLBeM Ty0ATj1w==; Received: by zero.zsh.org with local id 1rgr8U-000OJC-HU; Sun, 03 Mar 2024 19:04:34 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ej1-f51.google.com) smtp.remote-ip=209.85.218.51; 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-f51.google.com ([209.85.218.51]:45080) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rgr8B-000O07-EW; Sun, 03 Mar 2024 19:04:16 +0000 Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a44cdb2d3a6so169764966b.2 for ; Sun, 03 Mar 2024 11:04:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20230601.gappssmtp.com; s=20230601; t=1709492655; x=1710097455; 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=+Ucw2Qrm1j9mBky82Z26gMPKDjXOpjSJs6scAp7kTi4=; b=p1OCaRBLmna35Xsrr/+zLcNPlRPPq5aek1r6eieevZN2UanCwpkE8tjzdyVz1zbVfN a1qnqe+S4yH5mu16zdOtotIirjCc4ubtK2/gQkhCb+domYG/gg5X1j5G04PXRIdU22WJ ac+zE5XPJtYbJJkd47K9ak2hKaXHezcvueypAIHamofG4I2JVNGZ1AX7Q92buzK5dTPu 3o7C0KvZPbXoaADydzQ87vYtoo2jpRxBq5CjiDt103N85nQIwwUBmg5CqzfbloQNj1o+ 2HeKJb06sjE3q+33qiEOrOEgA2frdYXR7iG1h6CS9YaH/bSap1nmC3qsgkZ36LSNaD+L hC6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709492655; x=1710097455; 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=+Ucw2Qrm1j9mBky82Z26gMPKDjXOpjSJs6scAp7kTi4=; b=a+nsv3FgHEdA3MuADPCV5aXWBAjYIKOT+wUGLhwxIdSfDbwnk235nSBG9s4aQYRZhR A3FJxrgFfHf0ijyTv0T6DkUN8MQ72/TMui2cFRhpbfQU2+vw64Vi3PTJs9ev01tlf1ZW Bd/P6hapa2lnKqJaoI67QviWo6065WKGj8V8K+NprzsZCnAq3h97kp8DQsaSQnDHxQRQ Q06Rme9f/wxMBTNV1l5+s6JNtzAR9P58xRsNjqSR2d0x4tdZcf1HFBePMFOUH7szFDuw gfh3Npg9VfhVoZLg8JRUFx3P8C4J3XcfS9G3TYE+HAP7o6WOy0z8gmtMEHWPjN6t+rK/ K61A== X-Gm-Message-State: AOJu0Yyt9q4b0FvVgWflNAZ6oa1p1z48a4Zik3LJyH57Xit23YK1aVCM 8U20vWRvkUnD0FOHiXSkBz/dbOFhhzKiWtVCuBcLXcGRB1WgZTF1WewexUK511cSiBEQ4qNe8rz 4zPDhoV1Tzi+6B2Tw4IUc2pdQe0izQkvlVafh1aG9T4B7CAHsSg== X-Google-Smtp-Source: AGHT+IH6aviC/wyaan6tewgeh5X5eq4/BBvRHThI0O6gu5St0IQz2fnWr1DQRu4JXxMG+LvEGzeMghHjASJS0M1fy8o= X-Received: by 2002:a17:906:230b:b0:a44:80f0:1883 with SMTP id l11-20020a170906230b00b00a4480f01883mr5304478eja.42.1709492654509; Sun, 03 Mar 2024 11:04:14 -0800 (PST) MIME-Version: 1.0 References: <20240211070042.4j37hkgjjn3dfjqd@chazelas.org> <20240220210553.g6imt3op6zahz4pa@chazelas.org> <20240221201215.anpjcfav6na55gg6@chazelas.org> <20240301182238.tpyajwblbam5bxw7@chazelas.org> <20240303134413.74c7trikf73g5kjy@chazelas.org> In-Reply-To: <20240303134413.74c7trikf73g5kjy@chazelas.org> From: Bart Schaefer Date: Sun, 3 Mar 2024 11:04:03 -0800 Message-ID: Subject: Re: Up-scope named references, vs. ksh To: Zsh hackers list Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 52654 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 Sun, Mar 3, 2024 at 5:44=E2=80=AFAM Stephane Chazelas wrote: > > If that one can be fixed then why can't the main one Because the outer-scope parameter object already exists in "that one". As I keep saying, the problem is with creating a new parameter at a lower scope (counting 0 as the global scope) when a parameter of that name already exists at the current (greater than 0) scope. > typeset -n var=3D$1 > typeset value=3D$2 If the parameter is magically created "in advance" (at the point of "typeset -n") then it only works for global scalars -- if you try to create an array using "var" you run into baffling stuff like this: assign:3: value: attempt to assign array value to non-array I think it's much more consistent for dynamic scoping to apply at the time $var is referenced or assigned. The patch in workers/52650 allows something like this to work: assign() { typeset value=3D$2 typeset -nu var=3D$1 # ignore local $value case ${(t)var} in (*scalar*) var=3D$value;; (*array*) var=3D( $value );; (*) print -u2 cannot assign;; esac } declare -a value assign value x If a function wants to be able to actually add things to its calling scope without fear of name clashes, it has to use unique local names (e.g., a namespace). But with dynamic scoping it remains the case that you can't add a name to the global scope if any function in the call chain has pre-empted that name -- named references don't change this basic rule.