Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: All the way up or current scope
- X-seq: zsh-workers 53644
- From: Oliver Kiddle <opk@xxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: Philippe Altherr <philippe.altherr@xxxxxxxxx>, Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: All the way up or current scope
- Date: Tue, 20 May 2025 23:40:46 +0200
- Archived-at: <https://zsh.org/workers/53644>
- In-reply-to: <CAH+w=7YSh+__SXZKZ8KLytaT5uby-E6LbQyoaw1yeuWO64+TjQ@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAGdYchv84+isv2Y5B+WJtfz7cGtX-L7br+ZUgqshZC2Tc1OoOA@mail.gmail.com> <CAH+w=7aZjPT6xr5uEUL_s1PmuRh9hjZKZ=YvCuCJyE6Ye9iurw@mail.gmail.com> <CAGdYchswJc0CrMm2dbhFRgu6F=8wRiWnjNff0FhqYacDH_KJLA@mail.gmail.com> <CAGdYchsS2_QuHWuSWU1661K5Z8JY4k0p_QAYygdPRu8-Dr3jUA@mail.gmail.com> <CAH+w=7amjvo42qqO-b3+4_bcKo4VJodJEzZe9EYih3Mmo8gLUg@mail.gmail.com> <CAGdYchuEL6cs=ACG08txwYP+4BJ_gFZp6hFyTq3K+dbbaPfVfA@mail.gmail.com> <CAH+w=7ZiwkMEQfdK=dpDMzPf9yy0yEZbUQ0J=EyUYVGk_tBJ1A@mail.gmail.com> <CAGdYchsm6=NiahMZj1W7KWDnLbeBQv7WW_y--+3E8g4T1jSagA@mail.gmail.com> <CAH+w=7YSh+__SXZKZ8KLytaT5uby-E6LbQyoaw1yeuWO64+TjQ@mail.gmail.com>
On 12 May, Bart Schaefer wrote:
> As I said earlier in this thread, we tried a pointer implementation
> and never got as far as what's now done. It ended up requiring
> reference counting. I believe Oliver still has the partly-finished
> code for that variation somewhere.
The main challenge with the pointer implementation was not the reference
counting but the various places in the code where zsh was causing the
pointer to be invalid such as by removing it and creating it anew when
changing a parameter's type. I did have fixes to most such cases and if
you think there's value in such refactorings, they could be resurrected.
The way that private variables are implemented also broke it and the
last time I rebased that code was sometime before they were added.
Reference counting would allow a local variable that has a reference
to persist after the scope ends which would have some interesting uses
but the current implementation enables other more useful things like
references to subscripts. While experimenting with reference counting I
repeatedly had nagging doubts about the wisdom of the approach and don't
for a moment think we should be considering it now that we have a decent
alternative implementation working.
I've not been in a position to try the latest patches and haven't
followed every word of the discussion but just to put in my thoughts on
some of the main points:
typeset -nu always being relative to declaration does seem to be the
most logical, sensible and useful behaviour. I believe this is what has
now been implemented and pushed.
Fixing typeset -n to the current scope (applying the -u0 Philippe
suggested by default) would seem counterintuitive to me. With the
default of dynamic scoping, I'm used to being able to just use variables
from parent scope. Digging into parent scopes should always be very much
explicit.
I can see the potential uses of being able to specify -u0 or -u2.
But I certainly agree with Bart that it would be better to get a new
release out sooner without more new inventions. Using numeric counts
seems somewhat ugly and you should have the effect of -u2 by creating
a -un reference to a -un reference. Only problem is there's no way
to change the second of those references given the name of the first
reference. With a reference passed to a for loop where that reference
is a reference to another reference, it could follow to the end of the
reference chain and iterate the final reference. Whether that reference
was defined with -u or not would determine the scope for each target in
the for loop.
Oliver
Messages sorted by:
Reverse Date,
Date,
Thread,
Author