\documentclass[]{article}
\usepackage{amsmath,graphicx,supertabular,hyperref,tabularx,ifthen}
\title{TIP \#184: Avoid Creating Unusable Variables}
\date{March 27, 2004}
\author{Miguel Sofer}
\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 \#184}&\textbf{Avoid Creating Unusable Variables}\\\hline
Author&

Miguel Sofer \tipmail{msofer}{users.sf.net}
\\
Created&Saturday, \(\text{27}^{\text{th}}\) March 2004\\
Type&Project\\
Tcl Version&\(8.5\)\\
State&Final\\
Vote&Done\\
Version&\tipversion$Revision: 1.4 $\\
Keywords&Tcl, upvar, global\\
Post History&\\
\hline\end{tabularx}\end{center}
\thispagestyle{empty}\pagestyle{empty}
\begin{tipabstract}

Both \textbf{upvar} and \textbf{global} can create unreachable variables: scalar variables whose name looks like an array element, e.g., a(b). This behaviour is documented in the \textbf{upvar} manpage. This TIP proposes that both \textbf{upvar} and \textbf{global} raise errors instead of creating such variables.
\end{tipabstract}
\tableofcontents\setcounter{page}{0}\clearpage\pagestyle{plain}

\section{Rationale}

As detailed in [Bug \#600812] [\url{http://sf.net/tracker/?func=detail&aid=600812&group_id=10894&atid=110894}], both \textbf{upvar} and \textbf{global} can create unreachable variables: scalar variables whose names looks like an array element.

One example is:
\begingroup\small\begin{verbatim}
   upvar 0 x(1) y(1)
\end{verbatim}
\endgroup

which creates a \textit{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:
\begingroup\small\begin{verbatim}
   proc a {} {
       global x(1)
       ...
   }
\end{verbatim}
\endgroup

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 \textbf{upvar} and \textbf{global} raise an error rather than creating such a variable, mimicking in this respect the behaviour of \textbf{variable}.

Note that a TIP is required because the behaviour of \textbf{upvar} is documented in the manual page, so that it cannot really be described as a bug:

\begin{quote}
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.
\end{quote}

\section{Reference Implementation}

There is a patch attached to the bug ticket [\url{http://sf.net/tracker/?func=detail&aid=600812&group_id=10894&atid=110894}] that implements this TIP.

\section{Copyright}

This TIP is in the public domain.

\section{Colophon}

\textit{TIP AutoGenerator --- written by Donal K. Fellows}
\end{document}
