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 3725 invoked from network); 6 Sep 2023 05:05:19 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 6 Sep 2023 05:05:19 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1693976720; b=O2qhjdArOCPtmUj7j9ffULNGUlRjHfBLy09BHISj6GYURzw0A11NAyRWaR/2I/PE+3ovv8V0n1 3+V4WbwaSKWSt5Y0JiKoLrPEEDw0nZc62ZZ/j1dCx2euNvbT/u8i9u1Y7HDlA0C7xS0RrmZIha wzcxgoTnXVM0iFH663dN94+MmNIVIs3FSSeTss9iamViG6bkBQGd2T31ejda+MfimkoUsQgNU+ hvQuo6t2hM7F+7UqTO7HPcV65K2590Jty1qvlUpcfqeO0e+T4QPfZFOMGWwcWERzmMLxJFetn+ qz6Mrxu6KuR6bIR8fIfolByTz2UCKu8N3DITgC5S+3jQeg==; 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=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=1693976720; bh=VEqbxc2KvF3/dUsyMpqo7hDVkw5Q7sV+5l7n00+brew=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:MIME-Version: DKIM-Signature:DKIM-Signature; b=Odk89akiPWHlTgd6MV/ZDe8eJRpXhLpT73Ccsj1u1Pobp+lMh8APlIUOc34F3ALChS1eX5fFBe 8X9H37J7ESDlbsC+7+OBaZCNxwJNGygIrMAlgiS/I2iLvwpWookoFSDqNVYMgxkryWtIfntBfD RsVIwMKPTACO0z7fEljGZHPDZkVn+Vyne01GKdz5gGVCyc/f39Fk+v70r+O43XFXWrAA481vBk ueQC5FizbM8euTQc9N12InGd51YcSajPPUo+b8F68xiKXO8RqB3/vk3wV+FTYnP10RrJ6k5aAi +prFCtmags5FUEHMgVxoT4V6Lr9CNOSjLu/WFSJCe57xPg==; 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:To:Subject:Message-ID: Date:From:MIME-Version:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References; bh=+QjTjEJe/5aTp70FyzwwLxNIHdmvt6C84Xxo7x0dAdM=; b=ePObwMDOhodVm1RmwDLHyLuNjS hb1P5f6gsFIsP3rg0H8lX0E9ye9Iw55iNXvdUMA8pYsReXW+0t/yNBz3TJpp+JC9CmhycZeDcG4un xj0b/7qeY/LEqK4vW5fglURulR51Ta9g64wuECp5mLjL9+3RdBVWbGZSN1gH4AcKK4VetCh/m59TW 6UiuOqwJQH75LoOGMa0hM3u3acqUxQXTO96CEc3g7JEFOp9QYx72Vy0tYOVuV9ku0bft8rU6qfjLT yE31qgUPM1ysTO+nyWd7cWqUtqVmadF8WdYmRRWRPZDa0hA07EPEIWN/0vL2DybiDzh4TT7JPanxi fbclPinw==; Received: by zero.zsh.org with local id 1qdkj8-000297-2P; Wed, 06 Sep 2023 05:05:18 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ed1-f46.google.com) smtp.remote-ip=209.85.208.46; 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-ed1-f46.google.com ([209.85.208.46]:51409) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1qdkiq-0001ph-EN; Wed, 06 Sep 2023 05:05:03 +0000 Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-52713d2c606so4563456a12.2 for ; Tue, 05 Sep 2023 22:04:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20230601.gappssmtp.com; s=20230601; t=1693976699; x=1694581499; darn=zsh.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=+QjTjEJe/5aTp70FyzwwLxNIHdmvt6C84Xxo7x0dAdM=; b=vi94237x1siqfsaLd3aJ1t2pR6mJCqoJ+eX2DXCUxpqRy7Aa1I+VmVhfAmkEwhNmHr Y6eSviXGCP7m08Mu3GPy/E40lJb6BZeYUNXY+O6iRI44bWTgTwleiUEPwXXhi1+/ewJT n5WKV1qio+Ah1jWbRYLRcI1Wn4pi9DjFnytNWARaW7oZ6nacoJA/MJ4e/byNsqibdXFv D5d9VXQC2+UaUmY/KHjlV7d3Fi9Q2K139KoqbVadi7CkJzKTc7kfQNjQjI6mAr7xOZnE z3izcXJgVHb+UWIhlIk7ZWHHlwVAGkmvgdEYxTELoMlnI2pkPkmwqtjOvpXXswrcts7C LgTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693976699; x=1694581499; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=+QjTjEJe/5aTp70FyzwwLxNIHdmvt6C84Xxo7x0dAdM=; b=E0aThuxguegjdz3pupPfamGMJ4P1a3cuafJ2TukhNCjDfNDRlQMhzXk8ZXhie4NiQE ITUwRgQt8dfQb7yl4IwqgL6F3SqhRBY3g+LDNR5xdhbVKpk7gsGt69sCBVnu2GuMV4yP PKnnjY98gFItUqCdh8Q4+TKvA6pLdodRpV1JyPmvGPmp3PU4HZdwehiF84aB8Hu/x4d0 gnLNRCQgK/gwvCiyDBbnQ4OtOfEKHfM6einXms011NejQ7aJZDknjRF6gj5iF5rhoy5i 5SAvMLg3SA5h/hEFNFdlcdkjDsE6nSBTwZr3tNl3ctvVVWOdnIiD2XrJb9jD8Akzf3+Q NDag== X-Gm-Message-State: AOJu0YzQA79iuDQjJ0raG1fdzPo4ryLL4DhsqIySA9GO8xcyIVe36cdK Ay3M7BIjc/3V9LwZ6nbZ1nCGqfQzyY1qbS9xaczN3iXS5MGqD4YQXYc= X-Google-Smtp-Source: AGHT+IH5tDuqdo43L9QfP2HdqL/oFYmZYrFVGoJ82+MaEBUcSquSlABSf8CEziw9MaTpPxMD6vpzgdOj3xz0kjg6eu8= X-Received: by 2002:a17:906:2091:b0:99d:e8da:c20b with SMTP id 17-20020a170906209100b0099de8dac20bmr1224389ejq.24.1693976698969; Tue, 05 Sep 2023 22:04:58 -0700 (PDT) MIME-Version: 1.0 From: Bart Schaefer Date: Tue, 5 Sep 2023 22:04:48 -0700 Message-ID: Subject: [PATCH 0/2] persistent locals (sort of) To: Zsh hackers list Content-Type: text/plain; charset="UTF-8" X-Seq: 52116 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: This is an idea that was seeded by the zsh-users question from Budi about "plain variable which is retaining its value all the time". Diffs to follow in two parts: Part 1: There doesn't seem to be any reason a named reference should not be declared "hideval" (-H). This just means that if it gets dumped out in a "typeset -p" output, you don't see what it refers to. A minor drawback is that this is also what an undefined "placeholder" named reference looks like. This bit isn't essential to the scheme, see below. Part 2: A new module zsh/param/persistent. It introduces a builtin "persistent" which acts like "local" except that when run again at the next call to the function, it restores the value from the previous call to the function (actually, to any function having the same name). Any assignment made in the arguments to "persistent" is ignored, so this looks very much like "static" in C, except that the name is visible to nested scopes as usual. This should probably be considered a proof of concept at the moment. The way it actually works: A namespace prefix is first generated based on the function name, so if the function is "foo" the namespace is ".persistent_foo." This means it can only be used in functions that have names in the form of simple identifiers; it'll produce an error if used outside a function or in an anonymous function or in any function with dots, hyphens, slashes, etc. in the name. This could be solved with some kind of function-name hashing, I suppose. The argument list is then walked and split into name and value at "=" as with typeset. Because this is a builtin, there can't be array assignments etc., which is a second drawback. Every name is prefixed with the namespace and checked for existence; iff it doesn't yet exist in the namespace, it's created with the specified value if any. Finally, and always, all the original names are created as named references to their counterpart in the namespace, using the hideval option from Part 1. The end result is that the calling function always has named references to the same hidden global variables. Only those references are re-created on every re-entry. A further change (or option) that could make this even more "static"-like would be to create the named references using "private". In fact I suppose this could even be merged into the "private" module. I debated copying that module's hack for creating a keyword, but decided against it.