zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Mikael Magnusson <mikachu@gmail.com>
Cc: Marlon Richert <marlon.richert@gmail.com>,
	Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: [BUG] zsh/param/private scoping error
Date: Wed, 1 Sep 2021 10:35:59 -0700	[thread overview]
Message-ID: <CAH+w=7a8XK9GqdLDx2k2sRki+DTju9k44r1Vr9FOJxWA7RPKAA@mail.gmail.com> (raw)
In-Reply-To: <CAHYJk3SsTAGeUrBkrQRcpzcMPg0xjTEDBkHVBs8hATi8HzjhPA@mail.gmail.com>

On Wed, Sep 1, 2021 at 10:00 AM Mikael Magnusson <mikachu@gmail.com> wrote:
>
> Ah, I misinterpreted one of the examples, I thought that this would
> work as you expect:
> () { private foo; () { typeset -g foo=bar } }
> (while this wouldn't:
> () { private foo; () { foo=bar } }
> )
>
> But in both cases it is an error (although only the latter prints a
> message and aborts execution), and foo is not set globally.

Something else has changed since the implementation of private, I
think, because this is not what I expected:

top () { private foo=top; mid }
mid () { typeset -g foo=middle; bot }
bot () { print $foo }
functions -t top

% top
+top:0> private foo=top
+top:0> mid
+mid:0> typeset -g foo=middle
+mid:0> bot
bot: foo: attempt to assign private in nested scope

What makes the expansion of $foo in bot into an assignment?

> In fact a typeset -g is needed on the global level before the function
> using private is called, which seems impossible for the innermost
> function to enforce.

As you can see from the "F:" test Marlon quoted, this is something I
eventually intended to change.  It's rather complicated because of the
way locals are implemented as a LIFO at each individual named entry in
the parameter table, rather than a LIFO of parameter tables.  Even
without private, "typeset -g" only reaches as far upwards as the most
recent local declaration of the name.


  reply	other threads:[~2021-09-01 17:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-01 11:49 Marlon Richert
2021-09-01 14:09 ` Daniel Shahaf
2021-09-01 16:21   ` Marlon Richert
2021-09-01 14:39 ` Bart Schaefer
2021-09-01 16:03   ` Mikael Magnusson
2021-09-01 16:11     ` Marlon Richert
2021-09-01 17:00       ` Mikael Magnusson
2021-09-01 17:35         ` Bart Schaefer [this message]
2021-10-03 21:55           ` Bart Schaefer
2021-10-04  4:54             ` Mikael Magnusson
2021-10-04 15:12               ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7a8XK9GqdLDx2k2sRki+DTju9k44r1Vr9FOJxWA7RPKAA@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=marlon.richert@gmail.com \
    --cc=mikachu@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).