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

Re: Up-scope named references, vs. ksh



On Mon, Mar 4, 2024 at 5:05 PM Oliver Kiddle <opk@xxxxxxx> wrote:
>
> Isn't defaulting to a scalar type fairly normal.

Sure, but Stephane wants a global that's a blank slate for anything to
be assigned to.  I don't think we have a way to do that -- the way the
implementation works in the absence of namerefs is to actually
remove/free the parameter and create a new one.  If there are locals
pointing to the global via pm->old, and the global gets removed, all
the locals are also destroyed.

> A different problem I'm finding is with not being able to hide the
> reference type of a variable in a called function:

That's actually "correct" -- from the doc:

 When a _named reference_ is created with 'typeset -n', all uses of PNAME
 in assignments and expansions instead assign to or expand RNAME.  This
 also applies to 'unset PNAME' and to most subsequent uses of 'typeset'
 with the exception of 'typeset -n' and 'typeset +n'

I admit this is a little weird when the named reference is inherited
from another scope.  The most recent FAQ entry that I patched actually
suggests using "private -n var" to prevent downward scope leakage of
namerefs.




Messages sorted by: Reverse Date, Date, Thread, Author