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 autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 25640 invoked from network); 10 Dec 2022 17:37:44 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 10 Dec 2022 17:37:44 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1670693864; b=EPrGq1iBMMpDeHOitNyFF7/gNnJAyanH0YsIpFUS6198yyce+KyESqzPxqIMs9ysZV+5xbYSzp cczHYzlcfr8RqewPva4+pqYzW9YOdj6CZS2QM2nW+0p2iFXMipaXYtN3mH7FlMVqvIKgQgD4uW kEZ5bkhE5u8IKCOnlFvVBFrG696rM+9xJt9juwJHiXuDD/cgY+E+sZ9pFCUJC8JKf4iuQdNhoC /38fD4cyI6KgwEg4zVzkksoXzJvV5jO6Ni9VB/8L1BXNK2/59t0A46iFx6pHUnfWkjAK2Y+xrZ kstY9gwRlovMIykeh1P5RkWcxcKjFcjy/9hgMBgjpozRew==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ed1-f48.google.com) smtp.remote-ip=209.85.208.48; 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=1670693864; bh=2enXFLAKNfx6NSdhKCrQYChjLOOSX20d0ZYwy5AQ5I8=; 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=Tpffwt9rVjoNlx+D7NzYN1jubSAvXvWi/GQ3PK2gHGQbRiDdd59nlk914eenFws94fr3QyT/TZ jonk/Kx5ytK5GRXpXRa5JH1p+HQFch+W862r/3LG7VEs0uT9zMeva9WKdILMslUeA8CVvXDUeZ 7NQQH92yxZ8MH82x9hvtWJw8qf1cnL0e38Q1fZUSRLSy9O0gbVJjnAuVxqrurfzlorwl+eb7mH hIhjYxFerq+v6D9jttktDmt9vcgsO4pJC6oPOCCOebabaLV68pi9Yk+k0DmcRbpQOcOOo7PAsc r/85g5jegnsVHW+cyAgpdrq8FcWq1wDNNAE9o7NBS1QdRA==; 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=S1bTqZ+ZgLn0EIODzmk/cayb+ZpEDqfy2T+ozqFdkIo=; b=pGn3Gt2GM1GWbamYDfj2AsZ1mV E0t81CW0gddJGx1a/p/GfsyMTpX3fC60oF2F3lwlKgAmJoszYLt5VEK4tdAbjAkBWJNu5CBIsMhBB 1BbmdwYTjN9i86D9sEaseeRnWPQ0Hm/RgQ8ifRA6Sf/Cpix/Y6gERQy1yszXessfKRcyxypAzFtv7 W3XPeoouucRStk70njx8zBAOL2h4J0iMVgshy6Q+9ODmKdWSwecREfj3LZAg/L6Hk1nDZXGLFgULo VsQFugSaDCjhBri26nnTHMBQDA6AVqFz3Rwa28AJi1lbu7Q8+puqtyQ8Ktb0Kef2zjiS3XRtXdIzF oKmqfqIQ==; Received: by zero.zsh.org with local id 1p43nD-000Agl-6x; Sat, 10 Dec 2022 17:37:43 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ed1-f48.google.com) smtp.remote-ip=209.85.208.48; 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-ed1-f48.google.com ([209.85.208.48]:35684) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1p43mc-000AMw-3O; Sat, 10 Dec 2022 17:37:07 +0000 Received: by mail-ed1-f48.google.com with SMTP id i15so7306411edf.2 for ; Sat, 10 Dec 2022 09:37:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20210112.gappssmtp.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=S1bTqZ+ZgLn0EIODzmk/cayb+ZpEDqfy2T+ozqFdkIo=; b=4OJlSKFSO6+KD6IQ3cqhWtIX6t+lEqRZyqkkF6hc0DFb64W4D6TT5c9hNeUpdW+Lex OnUyHUX5RkfHv30XfvzPOvRulNTh9A662pyWJipaOsC8y7cLwb0PuHVWkdA3OYLB07Ya BZEzlLyd9pDu1MEVPZwXJPunpdAroMo1gAI0WsncFBevnnjyAsWcxu2wtTGf8ddYezMp v4cYIOWHX6rw4x+fIzTHEHmQIGtTnjHS4FVIHd/O6awhqYmOMgGlHVgZw+1h79O4M1HU fJdn56c6GX8R4W0zTFrhVhyXlClvTel32DScpVtRi499rFDYip5nJdX5mODIy4viXBRe jbxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc: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=S1bTqZ+ZgLn0EIODzmk/cayb+ZpEDqfy2T+ozqFdkIo=; b=1JJXJzyaYEwolb6sG3+/RlCE8w6F6gndH79nQeI6LHHhjzwa39i///EvCvGesyUog8 6P3ooOqBV7Mn/RLFOykYcbA3ZMsTZH84LJA38aNcMuVZ9nlCv2be/oH2h9qJ/O8x+b+W ng2cakoE8tejnLQdyJWnYblg23+WGYMEPEGJ7gGXUj9UJuegcc8MqJJeVaW1MzxKUlIa LjaMa/w/R0nzu89d8OXWNgHroiH8QViIMNJs3nVEWVCaFmjwqsv3FDYvpTwubDCU8KqV UasuVqSf0Fwd314UIRYo2JJKnHz/CsDgqxue1mTofVrx1mIR+oUlpVfZyM9QHVnZckFp nj4A== X-Gm-Message-State: ANoB5pldxp3TOo9Jb/CNECWRCeRt9IlxH3XtQnr1EdUd44+qtLGNXVI3 uBlddifY1Y1QuaIZivOKrr0U0UoAOZ75d7y1ixBRsA== X-Google-Smtp-Source: AA0mqf4SZH6c3Xxt/G5HTMbuIX5T9nanZZjqg4ao/+3detm4NwtfMCy0+4aA6spgj3R/wqRLQVBvgcn3/hQi2Cn9N/k= X-Received: by 2002:a05:6402:1013:b0:463:f3a:32ce with SMTP id c19-20020a056402101300b004630f3a32cemr69755843edu.366.1670693824886; Sat, 10 Dec 2022 09:37:04 -0800 (PST) MIME-Version: 1.0 References: <9e3026aa-39a1-dd50-4d29-a64724d4eaaf@irit.fr> <20221208082103.zg44mrv77jrizsaj@chazelas.org> <20221208100215.k2qcqdqgjlzwbdh7@chazelas.org> In-Reply-To: From: Bart Schaefer Date: Sat, 10 Dec 2022 09:36:53 -0800 Message-ID: Subject: Re: Private variables not private enough? (Was: Get cursor position (Was: [bug report] prompt can erase messages written on the terminal by background processes)) To: Philippe Altherr Cc: Zsh hackers list Content-Type: text/plain; charset="UTF-8" X-Seq: 51177 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 Sat, Dec 10, 2022 at 7:03 AM Philippe Altherr wrote: > > Case 1 to 4 show that both "typeset -g" and "print -v" are able to set a global variable independent of whether the variable already exists (case 1-2) or not (case 3-4). This is true if the variable is not already declared local at some enclosing scope. Shell variables are dynamically scoped, defaulting to global except when in the argument list of "typeset" and related declarations. Despite the apparent mnemonic, the only effect of -g is to skip the current scope before selecting the enclosing dynamic scope. > Case 7 and 8 show that the same isn't true if the global variable doesn't already exist. I find this very counterintuitive. With truly private variables, I don't see why case 7 and 8 should exhibit a different behavior than case 3 and 4. >> 7:v= >> (anon): v: attempt to assign private in nested scope Case 7 was a bug fixed by workers/49456. Case 8 has the wrong error message. In zsh-5.9, both 7 and 8 produce the error (anon): v: can't change parameter attribute This is documented (last sentence of this paragraph): * Within any other function called by the declaring function, the private parameter does _NOT_ hide other parameters of the same name, so for example a global parameter of the same name is visible and may be assigned or unset. This includes calls to anonymous functions, although that may also change in the future. However, the private name may not be created outside the local scope when it was not previously declared. This limitation is enforced by the internal implementation of dynamic scoping in zsh as a stack of parameter declarations. There's no way to "unshift" a new element onto the stack at an enclosing scope.