[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: RFE: Fix the name collision issues and typing issues with namerefs,

From: Chet Ramey
Subject: Re: RFE: Fix the name collision issues and typing issues with namerefs, improve various issues for function libraries
Date: Sat, 17 Jun 2017 20:23:06 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.1.1

On 6/14/17 12:04 PM, address@hidden wrote:
> This is relevant to my interests!
> So first off, the circular reference problem with "declare -n"
> apparently doesn't exist in Korn Shell: If you "typeset -n x=$1", and
> $1 is "x", it's not a circular reference. The nameref seems to take
> the origin of the name into account when creating the nameref: If $1
> is used to provide the name for a nameref within a function, then the
> nameref refers to a variable in the scope of the function's caller.
> But if the name for the nameref is taken from another parameter, or a
> string literal, then the variable is drawn from the scope of the
> function itself. It seems a little "black magic" in a way but it has
> the benefit of neatly matching some important common use-cases. I
> think Bash should either adopt something similar, or provide another
> mechanism to exclude function-local variables from nameref
> construction.

I've gotten a suggestion that function-scope circular references should
always be resolved beginning at the previous scope, but I haven't done
anything to implement that yet.

There are a couple of problems that make it less clean to implement the
Korn shell mechanism. First, declare is a shell builtin, which means that
its arguments are expanded before it sees them. x=$1 and x=x both look
the same to declare when it sees them. The second is dynamic scoping,
which makes resolution tricker. The korn shell uses static scoping, so it
only has to look at the current scope and the global scope (which makes
the x=$1 case even more irregular).

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]