TIP #471: ADD [INFO LINKEDNAME] INTROSPECTION COMMAND ======================================================= Version: $Revision: 1.1 $ Author: Mathieu Lafon State: Draft Type: Project Tcl-Version: 8.7 Vote: Pending Created: Friday, 05 May 2017 URL: https://tip.tcl-lang.org471.html Post-History: ------------------------------------------------------------------------- ABSTRACT ========== This TIP proposes to improve link variable introspection by providing a new *info linkedname* command. RATIONALE =========== This TIP is related to discussions about [TIP #457] and the *-upvar* extended argument specifier. Adding an intropsection command to get the name of the variable linked to is more Tcl-ish than automatically adding a local variable with the linked name. The proposed command is not restricted to [TIP #457] usage as this can also be used for a link variable created by other means, using the *upvar* command for example. SPECIFICATION OF THE PROPOSED CHANGE ====================================== There should be a new subcommand of *info* created with the following syntax: *info linkedname* /varname/ The /varname/ should be the name of a variable that has been linked to another variable (e.g., with *upvar*, *global*, *variable* or *namespace upvar*), and the result of the command will be the name of the variable linked to. REFERENCE IMPLEMENTATION ========================== The reference implementation is available in the info-linkedname [] branch. The code is licensed under the BSD license. IMPLEMENTATION NOTES ---------------------- Depending on the linked variable, the name is found using different methods: * The name of a variable present in a hash table (globals, local variables created at runtime, ...) is retrieved using the hash key; * The name of an array element is built using the name of the array and the index name, retrieved using the hash key. A new field is added to the TclVarHashTable sructure to access the related array variable from the array element; * The name of a compiled local variable is searched in current or upper call frames. COPYRIGHT =========== This document has been placed in the public domain. ------------------------------------------------------------------------- TIP AutoGenerator - written by Donal K. Fellows