TIP #184: AVOID CREATING UNUSABLE VARIABLES ============================================= Version: $Revision: 1.4 $ Author: Miguel Sofer State: Final Type: Project Tcl-Version: 8.5 Vote: Done Created: Saturday, 27 March 2004 URL: https://tip.tcl-lang.org184.html Post-History: ------------------------------------------------------------------------- ABSTRACT ========== Both *upvar* and *global* can create unreachable variables: scalar variables whose name looks like an array element, e.g., a(b). This behaviour is documented in the *upvar* manpage. This TIP proposes that both *upvar* and *global* raise errors instead of creating such variables. RATIONALE =========== As detailed in [Bug #600812] [], both *upvar* and *global* can create unreachable variables: scalar variables whose names looks like an array element. One example is: upvar 0 x(1) y(1) which creates a /scalar/ variable named y(1) that is linked to the element 1 of the array x. However, there is no way for a tcl script to read or write such scalar variables, the parser will interpret that name as referring to an element of the array named y. Another example is: proc a {} { global x(1) ... } which will create a scalar local variable named 'x(1)', linked to the element 1 of theglobal array x. Again, this variable is unreachable. This TIP proposes *upvar* and *global* raise an error rather than creating such a variable, mimicking in this respect the behaviour of *variable*. Note that a TIP is required because the behaviour of *upvar* is documented in the manual page, so that it cannot really be described as a bug: MyVar is always treated as the name of a variable, not an array element. Even if the name looks like an array element, such as a(b), a regular variable is created. REFERENCE IMPLEMENTATION ========================== There is a patch attached to the bug ticket [] that implements this TIP. COPYRIGHT =========== This TIP is in the public domain. ------------------------------------------------------------------------- TIP AutoGenerator - written by Donal K. Fellows