\documentclass[]{article}
\usepackage{amsmath,graphicx,supertabular,hyperref,tabularx,ifthen}
\title{TIP \#323: Do Nothing Gracefully}
\date{August 06, 2008}
\author{Colin McCormack, Don Porter, Kevin B. Kenny}
\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 \#323}&\textbf{Do Nothing Gracefully}\\\hline
Author&

Colin McCormack \tipmail{colin}{chinix.com}
\par
Don Porter \tipmail{dgp}{users.sf.net}
\par
Kevin B. Kenny \tipmail{kennykb}{acm.org}
\\
Created&Wednesday, \(\text{6}^{\text{th}}\) August 2008\\
Type&Project\\
Tcl Version&\(8.6\)\\
State&Final\\
Vote&Done\\
Version&\tipversion$Revision: 1.6 $\\
Post History&\\
\hline\end{tabularx}\end{center}
\thispagestyle{empty}\pagestyle{empty}
\begin{tipabstract}

A number of Tcl's built-in commands currently raise errors when given arguments that would cause them to do nothing. This proposal asks that they instead simply do nothing gracefully.
\end{tipabstract}
\tableofcontents\setcounter{page}{0}\clearpage\pagestyle{plain}

\section{Rationale}

With the introduction of \{*\} syntax in Tcl 8.5 and its ability to convert one original word into zero words when an empty list is expanded, scripts using the syntax are forced to check for the empty list when passing expanded arguments to a command taking variable numbers of arguments, but arbitrarily rejecting zero arguments. For example,
\begingroup\small\begin{verbatim}
 variable {*}$dict
\end{verbatim}
\endgroup

will currently fail if \$dict has no entries. Letting no-ops simply be no-ops rather than errors greatly lightens the programming burden on callers. There may be some marginal performance benefits as well.

Furthermore, there is no sound reason to constrain the argument count of these commands to be positive when an argument count of zero has a natural interpretation as a no-op. There is an elegance in permitting a function to range coherently over the complete domain.

\section{Proposal}

The syntax of the following commands shall be revised as described:
\begin{enumerate}
\item{}
\textbf{file delete} --- accept zero pathnames.
\item{}
\textbf{file mkdir} --- accept zero directories.
\item{}
\textbf{global} --- accept zero variable names.
\item{}
\textbf{glob} --- accept zero patterns, returning list of zero matching files (with \textbf{-nocomplain}) or ``no matches'' error.
\item{}
\textbf{lassign} --- accept zero variable names. [\url{https://sourceforge.net/support/tracker.php?aid=1671880}]
\item{}
\textbf{linsert} --- accept zero elements. [\url{https://sourceforge.net/support/tracker.php?aid=1672056}]
\item{}
\textbf{lrepeat} --- accept both \textit{number} = 0 and zero elements. [\url{https://sourceforge.net/support/tracker.php?aid=1671951}]
\item{}
\textbf{my variable} --- accept zero variable names.
\item{}
\textbf{namespace upvar} --- accept zero variable names.
\item{}
\textbf{tcl::tm::path add} --- accept zero paths.
\item{}
\textbf{tcl::tm::path remove} --- accept zero paths.
\item{}
\textbf{variable} --- accept zero variable names. [\url{https://sourceforge.net/support/tracker.php?aid=1881284}]
\end{enumerate}

\section{Compatibilty}

The proposed changes convert errors into no-ops. There should be no compatibility concerns with those. 

\section{Implementation}

When an implementation patch is completed, it will be logged in the SF Tracker and noted here.

\section{Exclusions}

Some other candidates for this treatment are intentionally left out of this proposal where for various reasons their conversion is complicated in some way, or the benefits of conversion are not as clear cut. These other commands might still be revised in a similar way, but are left for other TIPs to accomplish it so that this TIP can focus only on the low-hanging fruit.
\begin{enumerate}
\item{}
\textbf{after idle}
\item{}
\textbf{dict exists}
\item{}
\textbf{dict set d} \textit{val} (no \textit{key} argument)
\item{}
\textbf{dict unset d} \textit{val} (no \textit{key} argument)
\item{}
\textbf{dict update d} \textit{script} (no \textit{key varName} arguments)
\item{}
\textbf{eval}
\item{}
\textbf{expr}
\item{}
\textbf{file join}
\item{}
\textbf{interp eval}
\item{}
\textbf{namespace eval}
\item{}
\textbf{parray} [\url{https://sourceforge.net/support/tracker.php?aid=1739221}] This feature request is more about tolerating errors than about expanding acceptance over a complete input domain. Not in the spirit of this TIP.
\item{}
\textbf{uplevel}
\item{}
\textbf{upvar} --- presence of the optional \textit{level} argument makes this one messy.
\end{enumerate}

\section{Epilogue}

Proposed changes to \textbf{string first}, \textbf{string last}, and \textbf{string replace} in earlier revisions of the TIP that were approved by the vote have been rescinded after testing during the implementation phase revealed greater than expected issues with the incompatibilities those changes introduced.

\section{Copyright}

This document has been placed in the public domain.

\section{Colophon}

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