\documentclass[]{article}
\usepackage{amsmath,graphicx,supertabular,hyperref,tabularx,ifthen}
\title{TIP \#142: Search Path Variable to Lookup Command Names in Namespaces}
\date{July 23, 2003}
\author{Ulrich Schoebel}
\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 \#142}&\textbf{Search Path Variable to Lookup Command Names in Namespaces}\\\hline
Author&

Ulrich Schoebel \tipmail{ulrich.schoebel}{sigos.de}
\\
Created&Wednesday, \(\text{23}^{\text{rd}}\) July 2003\\
Type&Project\\
Tcl Version&\(8.5\)\\
State&Withdrawn\\
Vote&Pending\\
Version&\tipversion$Revision: 1.3 $\\
Keywords&namespace, command lookup, search path\\
Post History&\\
\hline\end{tabularx}\end{center}
\thispagestyle{empty}\pagestyle{empty}
\begin{tipabstract}

This TIP adds a Tcl variable to define the search path for command name lookup across namespaces.
\end{tipabstract}
\tableofcontents\setcounter{page}{0}\clearpage\pagestyle{plain}

\section{Rationale}

Command names (as well as variable names) are currently looked up first in the current namspace, then, if not found, in the global namespace.

It is often very useful to hide the commands defined in a subnamespace from being visible from upper namespaces by \textit{info commands namespace::*}. On the other hand, programmers want to use these commands without having to type a qualified name.
\begin{itemize}
\item{}
Example:
\begingroup\small\begin{verbatim}
 namespace eval ns1 {
   proc p1 {} {
     puts "[p2]"
   }
 }

 namespace eval ns1::ns2 {
   proc p2 {} {
     return hello
   }
 }
\end{verbatim}
\endgroup
\end{itemize}

Evaluation of \textit{ns1::p1} would currently lead to an error, because \textit{p2} could not be found. Even worse, if a procedure \textit{p2} exists in the global namespace, the wrong procedure would be evaluated.

\section{Proposal}

Add a variable \textit{tcl\_namespacePath} or, to avoid confusion with variables containing file system paths, \textit{tcl\_namespaceSearch}, that contains a list of namespaces to be searched in that order.

The default value would be \textit{[list [namespace current] ::]}.

In the above example \textit{tcl\_namespacePath} would be set to \textit{[list [namespace current] [namespace current]::ns2]}. \textit{p2} would be found and not unintentionally be substituted by \textit{::p2}.

\section{Alternative}

For ease of implementation and, maybe, for programmers convenience it might be useful to always prepend the contents of this variable with \textit{[namespace current]}. The programmer expects a certain ``automatism'' for this component of the search path.

Then the default value would be \textit{::}.

\section{Implementation}

To be done when this TIP is accepted.

\section{Notice of Withdrawal}

This TIP was Withdrawn by the TIP Editor following discussion on the tcl-core mailing list. The following is a summary of reasons for withdrawal:

\begin{quote}
Insufficiently subtle. 52 will break any code that assumes the current behaviour (and you can bet someone will have that assumption) and 142 doesn't let two namespaces have different search paths (unless the variable is always interpreted locally, which just creates bizarre variable name magic.)
\end{quote}

\section{Copyright}

This document is placed in the public domain.

\section{Colophon}

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