\documentclass[]{article}
\usepackage{amsmath,graphicx,supertabular,hyperref,tabularx,ifthen}
\title{TIP \#45: Empty index lists for [lindex] and [lset]}
\date{July 18, 2001}
\author{Kevin Kenny, Don Porter}
\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 \#45}&\textbf{Empty index lists for [lindex] and [lset]}\\\hline
Author&

Kevin Kenny \tipmail{kennykb}{acm.org}
\par
Don Porter \tipmail{dgp}{users.sourceforge.net}
\\
Created&Wednesday, \(\text{18}^{\text{th}}\) July 2001\\
Type&Project\\
Tcl Version&\(8.4\beta1\)\\
State&Final\\
Vote&Done\\
Version&\tipversion$Revision: 1.9 $\\
Keywords&lindex, lset, multiple arguments, sublists\\
Post History&\\
Discussions To&news:comp.lang.tcl,mailto:kennykb@acm.org\\
\hline\end{tabularx}\end{center}
\thispagestyle{empty}\pagestyle{empty}
\begin{tipabstract}

TIP's \#22 and \#33 contain an oversight in specifying the behavior of the multi-argument forms of \textit{lset} and \textit{lindex} when an empty index list is specified. The intended behavior is that an empty list of indices designates the entire list.
\end{tipabstract}
\tableofcontents\setcounter{page}{0}\clearpage\pagestyle{plain}

\section{Rationale}

In the discussion of \cite{tip33} ([\url{http://www.geocrawler.com/archives/3/7375/2001/5/0/5784409/}]), Jim Ingham pointed out that the list of indices presented to the multi-argument forms of \textit{lindex} and \textit{lset} is analogous to a database cursor. This cursor is conceptually navigating a tree structure; the command:
\begingroup\small\begin{verbatim}
  lindex $list {1 2 3}
\end{verbatim}
\endgroup

means, ``extract the sublist at index 1 in \$list, the sublist at index 2 in that list, and the element at index 3 in that list''.

When implementing this functionality, the author of this TIP realized that \cite{tip22} and \cite{tip33} provide no way to address the root of the tree -{}- the entire list being manipulated. An empty list of indices is a convenient means of specifying the root.

\section{Specification}
\begin{enumerate}
\item{}
The specification of \textit{lindex} in \cite{tip22} shall be amended so that the forms:
\begingroup\small\begin{verbatim}
  lindex list
\end{verbatim}
\endgroup

and
\begingroup\small\begin{verbatim}
  lindex list {}
\end{verbatim}
\endgroup

will return the value of the entire list. The \textit{list} parameter is not required to be a well-formed Tcl list when this form is used.
\item{}
The specification of \textit{lset} in \cite{tip33} shall be amended so that the forms:
\begingroup\small\begin{verbatim}
  lset var value
\end{verbatim}
\endgroup

and
\begingroup\small\begin{verbatim}
  lset var {} value
\end{verbatim}
\endgroup

will simply store the supplied value into the variable named \textit{var}. Neither the old nor the new value of \textit{var} is required to be a well-formed Tcl list when this form is used. The return value of the operation, as with all other uses of \textit{lset}, is the new value of \textit{var}.
\end{enumerate}

\section{Reference implementation}

Work progresses on implementing this functionality; the currently committed version is on SourceForge in the branch labeled, \textit{kennykb-tcl-22-33}.

\section{Discussion}

Since this proposed change introduces syntax that is expressly forbidden in \cite{tip22} and \cite{tip33}, it does not have any impact on backward compatibility. For the same reason, the author thought it unwise to proceed with its implementation without a vote of the TCT.

\section{See Also}

\cite{tip22}, \cite{tip33}.

\section{Copyright}

This document has been placed in the public domain.

\section{Colophon}

\textit{TIP AutoGenerator --- written by Donal K. Fellows}
\begin{thebibliography}{TIP \#2}
\addcontentsline{toc}{section}{References}
\bibitem[TIP \#22]{tip22}
David Cuthbert,
Kevin Kenny,
Don Porter,
Donal K. Fellows,
\emph{Multiple Index Arguments to lindex},
on-line at \url{http://purl.org/tcl/tip/22.html}
\bibitem[TIP \#33]{tip33}
Kevin Kenny,
\emph{Add 'lset' Command to Assign to List Elements.},
on-line at \url{http://purl.org/tcl/tip/33.html}
\end{thebibliography}
\end{document}
