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

Re: All the way up or current scope



On Sat, May 10, 2025 at 2:01 PM Philippe Altherr
<philippe.altherr@xxxxxxxxx> wrote:
>
> The ksh documentation states that an important use case of typeref -n is to be able to access variables from the calling function. I was wondering how that could work with static scoping where each function only ever sees variables defined by itself. The trick apparently is that if the named reference is initialized in the typeref statement with a value that contains $1 (or $2, $3, ...) then it refers to a variable of the calling function.

Yes; zsh can't (and won't) perform that sort of magic, because even
with the keyword implementation of "typeset" the substitution of $1
for its value is done too early to treat it as special.  This is why
"typeset -n -u" was introduced in the first place.




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