\documentclass[]{article}
\usepackage{amsmath,graphicx,supertabular,hyperref,tabularx,ifthen}
\title{TIP \#471: Add [info linkedname] Introspection Command}
\date{May 05, 2017}
\author{Mathieu Lafon}
\urlstyle{sf}
\setlength{\parskip}{1ex}
\setlength{\parindent}{0pt}
\def\tipversion$#1${\texttt{\$#1\$}}
\def\tiplangle#1{\ensuremath{<}}
\def\tiprangle#1{\ensuremath{>}}
\def\tipbar#1{\ensuremath{|}}
\def\tipmail#1#2{\(\langle\){\small\expandafter\url{#1@#2}}\(\rangle\)}
\ifx\pdfoutput\undefined
\newcommand{\tipimage}[2]{\typeout{Make sure you download #1.eps}\ifthenelse{\lengthtest{0.8\textwidth>#2}\and\lengthtest{0pt<#2}}{\includegraphics{#1.eps}}{\includegraphics[width=0.8\textwidth]{#1.eps}}}
\newcommand{\tipxref}[1]{}
\newcommand{\tipxrefend}{}
\else
\newcommand{\tipimage}[2]{\typeout{Make sure you create #1.pdf}\ifthenelse{\lengthtest{0.8\textwidth>#2}\and\lengthtest{0pt<#2}}{\includegraphics{#1.pdf}}{\includegraphics[width=0.8\textwidth]{#1.pdf}}}
\pdfcatalog{/PageMode /UseOutlines}
\newcommand{\tipxref}[1]{\pdfannotlink attr {/C [0.5 0.5 1.0] /Border [0 0 1]} goto name {#1}}
\newcommand{\tipxrefend}{\pdfendlink}
\fi
\newenvironment{tipabstract}{\begin{abstract}}{\end{abstract}}
\begin{document}\maketitle
\begin{center}\begin{tabularx}{\linewidth}{|r@{: }X|}\hline
\textbf{TIP \#471}&\textbf{Add [info linkedname] Introspection Command}\\\hline
Author&

Mathieu Lafon \tipmail{mlafon}{gmail.com}
\\
Created&Friday, \(\text{5}^{\text{th}}\) May 2017\\
Type&Project\\
Tcl Version&\(8.7\)\\
State&Draft\\
Vote&Pending\\
Version&\tipversion$Revision: 1.1 $\\
Post History&\\
\hline\end{tabularx}\end{center}
\thispagestyle{empty}\pagestyle{empty}
\begin{tipabstract}

This TIP proposes to improve link variable introspection by providing a new \textbf{info linkedname} command.
\end{tipabstract}
\tableofcontents\setcounter{page}{0}\clearpage\pagestyle{plain}

\section{Rationale}

This TIP is related to discussions about \cite{tip457} and the \textbf{-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 \cite{tip457} usage as this can also be used for a link variable created by other means, using the \textbf{upvar} command for example.

\section{Specification of the Proposed Change}

There should be a new subcommand of \textbf{info} created with the following syntax:

\begin{quote}
\textbf{info linkedname} \textit{varname}
\end{quote}

The \textit{varname} should be the name of a variable that has been linked to another variable (e.g., with \textbf{upvar}, \textbf{global}, \textbf{variable} or \textbf{namespace upvar}), and the result of the command will be the name of the variable linked to.

\section{Reference Implementation}

The reference implementation is available in the info-linkedname [\url{http://core.tcl.tk/tcl/timeline?r=info-linkedname}] branch.

The code is licensed under the BSD license.

\subsection{Implementation Notes}

Depending on the linked variable, the name is found using different methods:
\begin{itemize}
\item{}
The name of a variable present in a hash table (globals, local variables created at runtime, ...) is retrieved using the hash key;
\item{}
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;
\item{}
The name of a compiled local variable is searched in current or upper call frames.
\end{itemize}

\section{Copyright}

This document has been placed in the public domain.

\section{Colophon}

\textit{TIP AutoGenerator --- written by Donal K. Fellows}
\begin{thebibliography}{TIP \#1}
\addcontentsline{toc}{section}{References}
\bibitem[TIP \#457]{tip457}
Mathieu Lafon,
Andreas Leitgeb,
\emph{Add Support for Named Arguments},
on-line at \url{http://purl.org/tcl/tip/457.html}
\end{thebibliography}
\end{document}
