Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH 1/3]: Add named references



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