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 58FB927B85 for ; Fri, 1 Mar 2024 21:35:11 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1709325311; b=m9LRIIJTbStGCNy7Vq293Ccjz9Z4+4myLd9ddu2ItPTgwsbiI/E7wrubIJuCrJojDHfJHLm9jP d8B6T86K7LloIEepn8N/IzJdqzIt4jYT1so5iBc2MnrPBdwpxf5oT0Mj8HaPInXHq2/BwfaG2A dE6Xl9hT0oBY5SUKcYdCpOM+C1XWNZUV2h0incXh9xtvJGMmVCfVaDAXazAi5Gn11mpYwGsBYL tAJ62HvZ/bSmPuGg9uaaD2+GHlUnmyar+Y4Q2TydVIAPyxjGam/82IQTQ78eLEOPXRVpVfmAnF XThA4ZT2lT9QjRrcwYJDS8b1nOjwGD72lgngyK8XLQa2/g==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ej1-f48.google.com) smtp.remote-ip=209.85.218.48; 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=1709325311; bh=Q4fRlkKRQiSFRO8idm12TZUwMTq3ozzVZiE4ON+qEJ8=; 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=YsQvU0dl/wGnFBJBMQGJciW0qTBmsgkSnaiNQdC4t48nnv0MaezCWmcYqSTgPdBioSCB+Hihxw LT2kI1Ma+w/cRdpl+CCCt8QNG1P0JMET+30JFfAjYQLwcTII3mLSkHRtzgYtpV4av7NHFOddLA gTUDBSpJHp9xXtlQe+kGhIYJ0zjUrLbqpbYfv0mlSCVQbpUmIsKG3AjfGc5VQI/j92iLCKLcde w8uWi+5tW9U5eBcg9RULjql2+uDJcmAxv/t9lQS85d/Tn0kQnrhSIyddFoNZB9yqKgiPT73aAZ yxACXlRk35jkkGiH5GFV+FtRVTWGE30ainPZWNRTNy23lA==; 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=oNVdWSXRdFmJafEAugCSLQwDbc9cZTbCak1rRu4zMZ8=; b=NpavY5MAkGHePDvQHwZI4oXtFs NKo5LaGO+RiodtZNOiZ9DgRcPi1EdLkkJvlw0Q/ZQuF41YFa4kp7N4a34L+qq2DZwAlSJIfX8Tkhw FEiAUurvl3Qr7La9CGCLRL0cQ+SugpeT7x8ivvMCodGW+9GMa6icDwJmdurAEwSBoY4u4FHgG/5W8 LYzYBgo1omkNUd+jWWN3JoneXMYPMHVXsxcTlq9lxk4Bv/S2n6UR8YQ3n36m1N+UUtPeFssowQN3/ NZi4H8fppkpZXQioLNQ3bL/Dac105eDpCtoKbtU1DZGIUyTcNdvDz0UTzrI0Upb/+pPP6Ti72rBPj Cs1fOWBg==; Received: by zero.zsh.org with local id 1rg9b5-000Pu0-Ag; Fri, 01 Mar 2024 20:35:11 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ej1-f48.google.com) smtp.remote-ip=209.85.218.48; 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-f48.google.com ([209.85.218.48]:43519) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rg9aU-000PYo-Bo; Fri, 01 Mar 2024 20:34:35 +0000 Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-a3ed9cae56fso686400366b.1 for ; Fri, 01 Mar 2024 12:34:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20230601.gappssmtp.com; s=20230601; t=1709325273; x=1709930073; 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=oNVdWSXRdFmJafEAugCSLQwDbc9cZTbCak1rRu4zMZ8=; b=QzXm+Y0juSaJ1QWuczIE3WUeHG5HL/jBHKWAa6rU6xyWSm8SHfggp+aqC66bYkQazK ScyJbSscjnp6w62wA5U+lVwRGslByI6AWM/coC+t/SNcNNeUPGfFtKM1ta0TPfGnfThF gaUpOtjTah0XEJyjPefSuxFRDAFF/Ogx/uWI3hu/FtEhw+c6Tq4dBk6tfJNqoG0Ym52m Dz3GaEH/8s35eNE2GS6Fc5K/wmhSt8mDSx3YBvgIhuIKONej1lUDJIy8mlpt7E8jhb3n mvYR7bhfHh0dUjkuX576GeHSRORcUmENrTLoUrCN/EwGehvTxDfjXrmF+vV40UC4hFho +F2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709325273; x=1709930073; 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=oNVdWSXRdFmJafEAugCSLQwDbc9cZTbCak1rRu4zMZ8=; b=gSAT7ji7DSDIVPA+b2plMMUVlFqkn/s3BLF0I9At8ejZK97JdfUN8tDJS+VOUHDx8g 9phuV0xmsYlzFa/JkzDIDF/G/AZj9lpV42nGhoya019PjKGqc0JfJtR21qG4R9comedI tcGK53u5wBx1VHjkRq0JP1H1RYsobSCsK5TNu/z6UtSr43oQkt9Am29GhKnjGdwZdRSF c9ebVvPgLQd54L6da+pd3IFo5bMZwDlFymMkEhvgDXODi30SXYCEz6WO3/CgcSGHoqZC tf9oOp1eI8swVu7V7TgPmnjUNSBBLEH8tasUYM6BUOWiyFoLCcw+pq3QMa0SVg/gbApb 4FTQ== X-Forwarded-Encrypted: i=1; AJvYcCW7THkEiHCkGpDsc3htWHBZeOQ3DFenwctLJ1RdfilsBpL16UDZlWicpa8zlLdsBDQtZVhY7CMwTfBBawqKjDrDTQ6j X-Gm-Message-State: AOJu0Ywq87DStyKm0s2Nvi03ewR9dTJAknD5ttR7bKN+flgaanLxJ0Nn wpB4bXByH/lvNkQkqyv6UxahOEAYmioiHc+bTxWLax4Av9ggpq3qBniHUvi+2JZKPTPe1S7nHgJ O1sY5Ny7f69CCSj8yBgoOKiuJLaMksbzO8wUV+Q0Fhxou/Uy47g== X-Google-Smtp-Source: AGHT+IFbCvSU7RucQMhor5Bnwp5ZjHG4ngCEx9udvV+MKN+LymWDhivFoFnn6Z4c7px/EDJUmoKGAAeCS+rjcPXBZVo= X-Received: by 2002:a17:907:1745:b0:a44:6b6b:a787 with SMTP id lf5-20020a170907174500b00a446b6ba787mr2332615ejc.37.1709325273559; Fri, 01 Mar 2024 12:34:33 -0800 (PST) MIME-Version: 1.0 References: <40726-1676098925.110777@U2kb.d0Pd.I9ml> <20240211070042.4j37hkgjjn3dfjqd@chazelas.org> <20240220210553.g6imt3op6zahz4pa@chazelas.org> <20240221201215.anpjcfav6na55gg6@chazelas.org> <20240301182238.tpyajwblbam5bxw7@chazelas.org> In-Reply-To: <20240301182238.tpyajwblbam5bxw7@chazelas.org> From: Bart Schaefer Date: Fri, 1 Mar 2024 12:34:21 -0800 Message-ID: Subject: Re: Up-scope named references, vs. ksh To: Bart Schaefer , Zsh hackers list Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 52644 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 1, 2024 at 10:22=E2=80=AFAM Stephane Chazelas wrote: > > 2024-02-28 21:16:13 -0800, Bart Schaefer: > > [...] The workaround in > > underlying C code would be to have "typeset -n r1=3Da" (again your > > example) implicitly create the global $a as early as possible. > [...] > > Couldn't typeset -n ref=3Dvar, when it finds that var is not set > create one in global scope with a "unset-but-referenced" flag Yes, that's what I just said. > and maybe a reference count associated with it Reference counting ends up being a pretty significant refactoring of the parameter code, we started down that path some time ago and didn't get satisfactory results. > Comparing with ksh93: You really can't, because ksh93 uses static scoping of locals where zsh uses dynamic scoping, and ksh also has special handling of "typeset -n ref=3D$1" (and other positionals) that is simply never going to happen in zsh. The upshot is that if we go with implicitly creating a variable in global scope, it doesn't solve the other reference issues -- so the question is, when we document the pitfalls of using upward-pointing named references, do we also break the dynamic scope paradigm for the specific case of nonexistent globals? > Imagine a function meant to create a variable whose name is passed as arg= ument That can't cause a serious difficulty because if you have such a function, the caller must know that the argument is a parameter name, and therefore must be able to create the parameter in the correct scope in advance. It's just not as syntactically sugary as ksh. Note that all of these situations also exist with builtins like zstat and even "print -v" that accept parameter names as arguments.