Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH 1/3]: Add named references
- X-seq: zsh-workers 52531
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, Oliver Kiddle <opk@xxxxxxx>, Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: [PATCH 1/3]: Add named references
- Date: Sun, 11 Feb 2024 10:14:40 -0600
- Archived-at: <https://zsh.org/workers/52531>
- In-reply-to: <20240211070042.4j37hkgjjn3dfjqd@chazelas.org>
- List-id: <zsh-workers.zsh.org>
- References: <CAH+w=7bd5tHQ8_ZFuyheUrTStm8pR826jH1LB-vMdEnv14nH0w@mail.gmail.com> <67689-1675827940.088548@BxvG.D9_b.7RzI> <CAH+w=7ZFq_MyNtPVetDt84Zp8dnCQXis3p=2sKP018GZ-VTd0g@mail.gmail.com> <12608-1675903622.800470@Xj82.e3y1.svhG> <CAH+w=7ZZUCqYe6w1ZqZZKR6iLsZH0SDDXyzwgTU93nxx6bmxjQ@mail.gmail.com> <66045-1675975796.128039@FBF_.0yMO.Y8fk> <CAH+w=7bcqc8SsRxsht0QFyXy=DYzj6nVaBFhdzQ5MrBB+yBz+A@mail.gmail.com> <CAH+w=7YVJO-HkneMpnfBbqBztPaXdXTD=mo-vHbdUW00TiFVBQ@mail.gmail.com> <40726-1676098925.110777@U2kb.d0Pd.I9ml> <CAH+w=7aKwKhdXjPo2FQG1GqjHQzX=5to_m6kZeL-UFfQh_XMtw@mail.gmail.com> <20240211070042.4j37hkgjjn3dfjqd@chazelas.org>
On Sun, Feb 11, 2024 at 1:00 AM Stephane Chazelas <stephane@xxxxxxxxxxxx> wrote:
>
> One difference with ksh93: if the target variable was not set at
> the time of the "typeset -n ref=target", then when ref is
> assigned it may end up refering to a local target
Hm. I think I can prevent that from happening (it wasn't intentional)
but I don't know if it's feasible to actually create a new variable at
the original scope, because of the implemention as a linked list of
scopes for each parameter -- it's not clear how to insert a variable
into the middle of the list.
> It can be worked around with a typeset -g $1 before the typeset -n var=$1
Is that really sufficient? Might the -g not select the wrong scope if
the string $1 was passed down a couple of layers? Seems to me you
have to avoid re-using a variable regardless, especially if you do
typeset -n var=
(create what I've been calling a "placeholder") and then assign to var
in some nested scope. This may particularly be true of the "for var
in ..." special case for namerefs.
Something I forgot to mention before regarding "_zslurp_var" -- if
you're going to a assume "typeset -n" then you can also assume
namespace syntax e.g. ".zslurp.var"
But the zslurp I put in the distribution was also meant to be somewhat
backward compatible so I didn't use namrefs or namespaces.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author