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.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 D3E90220D2 for ; Tue, 5 Mar 2024 06:44:27 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1709617467; b=JnZqNqT7GEjGB98YBGiYAFTegTGzbrgOZD19T/Vzeq1r2zGJkFQKzQGm6vsPgJmXyVi74agID8 1ReouckEQQu8s6Ld/MP44ahV4DpnSD1POw6nrkxAWTdpGn2IlpVNSJPwFFCQ/8ZuMU64bz+S1h oJrKqKGlOkjfmttgrEE+AwKR03o0HXMIBLU8aVQ4UXi3IFf2RxHJUvHnqZNPEBMV+SeTdHHgXC JE4OfQ6Z6S3Tzxr+jYs4ZRsCGLWphjJuUh+T97jAjl+n/BT2xBlpTyC5mW3NJBnB+CbYghXOcs DPRD5Md6KMWUOa00VpN+J4AjfZojRXLgmuxYPMamM0HxhQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ed1-f46.google.com) smtp.remote-ip=209.85.208.46; dkim=pass header.d=gmail.com header.s=20230601 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1709617467; bh=DFhI2Ohd6pY7R3Wa1+r+eiR8MuGIK78Ed58Z/32xzVY=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:Cc:To:Subject: Message-ID:Date:From:References:In-Reply-To:MIME-Version:DKIM-Signature: DKIM-Signature; b=Ygf4qvjXqYJsREbZP5uNTliJBf7hFxVu2uWJYiQjuIAh93QtN5zUpIGBcwur0X+fiFRn73k+7b /UpjNUdkEnmGZxrhGd6cioJX7fYr4mUqbJj96h6nmfQ6GSwcmsx9pg7oVRSMshr6i0O2anqmWC dfcN3pRnxJ5pFJDLK1ilfxmU8O0RsnU2NBuS8v4AJp4w2yNPBwnAtZ/agSoJFEv+lKJS/u+Gql 8Y4GdkCMccQf+mSwvLUyfvau6s4hSRBz80daFjwQxLfxzpiVkeA7VGV3aUku4qyZNKAo/6eODD es0M3eftp0UIGlfajN5f3nB5MtCHITQB20xRJH6LPlyGxA==; 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:Cc:To:Subject:Message-ID:Date:From:References:In-Reply-To: MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=FnUyCXxh01WHFakQOtmPV8BGwZY11sCxtse6iFt4RlM=; b=N9lUeFInJ5kFo0GqH1rdlqqpd5 XFKf7WSfUSSjnXo5lFLZr7/ZLj1w+28GGZK+/tw5MVMG1uQoSiZQSvRtKFOe+B0r+y19jat1ifNpn Rh7KsSP97DwKxUcqCvdN502OXzewIYFq294IowobMCI+Dj4dIP86Fw4vlEmYrgKZ2nHqo44b2BHCU VjQCvmfbUYHdA9bPLHod6+HqJl/0ognQx8GHIjJ2aY/siOf8qLWAvmo4TqUcQgUy0yvZ68fEbVFpb +guahoG1b+H3HpLh6SHZYsxX9/8qNAG6g8jpc5qBL8TXwlmhULJQK5D68mbk7WSt9qxM9Ph0p7VYj 8OKXRYog==; Received: by zero.zsh.org with local id 1rhNbG-000GtY-MH; Tue, 05 Mar 2024 05:44:26 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ed1-f46.google.com) smtp.remote-ip=209.85.208.46; dkim=pass header.d=gmail.com header.s=20230601 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-ed1-f46.google.com ([209.85.208.46]:61466) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rhNZw-000GXC-BB; Tue, 05 Mar 2024 05:43:05 +0000 Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-565a2c4cc1aso262299a12.2 for ; Mon, 04 Mar 2024 21:43:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709617384; x=1710222184; darn=zsh.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=FnUyCXxh01WHFakQOtmPV8BGwZY11sCxtse6iFt4RlM=; b=HRVCwQqf2Qv23Miv9aQEk/SH+52D/g9D3ZGZpoYFXgz4VDVQmL24VxTBxezWep6XdI ceFLPYoLVd+kuoeHXrXZxJi4Mpglw8TOFLnYlcPF2/nKZXR1jd9qrdF9+4KRJrbvgMLu 3lwVXFBgHdVwITAbF+igbFgQCMwolSC7kMHcUEqbsgHXzT7+cqWm5XSiIUWo1sMYK93d F7Msu/b040ohJ6lv4E7Tiu+DPLdTpm1f0/P5jEAI+oWMS3bOQORPUHD40V6jAvyhVDof P6kHfPF5j36Oy1QRts+fclAjFARY55rwhrh2nPWlrhrVhJ9KWK9FgTYnRYNOtk782Z3j KPqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709617384; x=1710222184; h=content-transfer-encoding:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FnUyCXxh01WHFakQOtmPV8BGwZY11sCxtse6iFt4RlM=; b=QQNJeT2gkvMGIjXitZIrxMy6g7OIP/ZgEwsnL8GZEKqAOV3yzKggKCFbCaTDWtrWth +8S27tbO3Vr4Kf4O5JNjdux388HevBKg4Omzbu6EdN36fBXHlQgOMdgkfchJiABmbYHS ptGq8Tifjo7t1d4I6r+FVTPw5WGUIXVchmbXJDmCVSZoWVMmPDdxO0aknRyUU0N8q4jK Yt79IOEEJWjFHggMZuo9eBkFJr3sZHsRWwxElXVs9YeDyFB2+XtECocWUOJ6wLNuGxJo OkI8mml9pNsJDjwmAnrUzJYbuxvx52Fwv7gdzWp4zmR0ki5AKVX+YxCi28FVKWCjeZEo c4ig== X-Gm-Message-State: AOJu0YzfTlmZLlbAzGW+AY+LDNeC1Fvntd+rJHMNlkOplmIfr2v6Shqu Dtc/DdTGrSMHK6lkfdKFrWY4c+IA+2zE16oN+8XEEjQEyvf4KsUYnfwADnkMr8dpsyZ2rA3X2Hm 1fyuFayeJAEKcT7aOCMjvmCf+VL18+g4P X-Google-Smtp-Source: AGHT+IE4KGkN8pPiC/G/Z90mfnk/X8AHzkGV09ADm+vhUrq7abQHjSIx6tD9YSbFbyU5zTaPi3RRUuYNGdyfpI3zzxw= X-Received: by 2002:a17:906:b08:b0:a45:248e:b253 with SMTP id u8-20020a1709060b0800b00a45248eb253mr3817422ejg.76.1709617383559; Mon, 04 Mar 2024 21:43:03 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a05:7208:5351:b0:7f:2ef1:5159 with HTTP; Mon, 4 Mar 2024 21:43:02 -0800 (PST) In-Reply-To: References: <20240220210553.g6imt3op6zahz4pa@chazelas.org> <20240221201215.anpjcfav6na55gg6@chazelas.org> <20240301182238.tpyajwblbam5bxw7@chazelas.org> <20240303134413.74c7trikf73g5kjy@chazelas.org> <20240303202756.7axmzy6gkohza2ra@chazelas.org> <90920-1709600703.280388@Hl_Q.k_r5.OUBX> From: Mikael Magnusson Date: Tue, 5 Mar 2024 06:43:02 +0100 Message-ID: Subject: Re: Up-scope named references, vs. ksh To: Bart Schaefer Cc: Zsh hackers list Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 52679 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 3/5/24, Bart Schaefer wrote: > On Mon, Mar 4, 2024 at 5:05=E2=80=AFPM Oliver Kiddle wrote: >> >> Isn't defaulting to a scalar type fairly normal. > > Sure, but Stephane wants a global that's a blank slate for anything to > be assigned to. I don't think we have a way to do that -- the way the > implementation works in the absence of namerefs is to actually > remove/free the parameter and create a new one. If there are locals > pointing to the global via pm->old, and the global gets removed, all > the locals are also destroyed. > >> A different problem I'm finding is with not being able to hide the >> reference type of a variable in a called function: > > That's actually "correct" -- from the doc: > > When a _named reference_ is created with 'typeset -n', all uses of PNAME > in assignments and expansions instead assign to or expand RNAME. This > also applies to 'unset PNAME' and to most subsequent uses of 'typeset' > with the exception of 'typeset -n' and 'typeset +n' > > I admit this is a little weird when the named reference is inherited > from another scope. The most recent FAQ entry that I patched actually > suggests using "private -n var" to prevent downward scope leakage of > namerefs. Is this possible to change? I feel like if "typeset myvar" (or "local myvar") cannot be depended on to create a local parameter, a lot of code will no longer be safe that previously was (in the sense that it doesn't break if calling code / the shell environmnet has certain parameters defined). Surely we cannot expect everyone to add +n to every single "local" statement? If the current behavior is wanted, one can always use typeset -g to get it, presumably? And that would be more backward compatible, right? Like say I have typeset -n foo=3DPS1 in my .zshrc because I don't like writing $PS1 manually, now any code I call which has a "local foo" is broken, which is not great. They have explicitly added their "local foo" to be able to use the name 'foo' regardless of the calling environment... "private -n foo" works in this case too, but I still hold my opinion. --=20 Mikael Magnusson