\documentclass[]{article}
\usepackage{amsmath,graphicx,supertabular,hyperref,tabularx,ifthen}
\title{TIP \#139: Publish Part of Tcl's Namespace API}
\date{June 03, 2003}
\author{Donal K. Fellows}
\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 \#139}&\textbf{Publish Part of Tcl's Namespace API}\\\hline
Author&

Donal K. Fellows \tipmail{donal.k.fellows}{man.ac.uk}
\\
Created&Tuesday, \(\text{3}^{\text{rd}}\) June 2003\\
Type&Project\\
Tcl Version&\(8.5\)\\
State&Final\\
Vote&Done\\
Version&\tipversion$Revision: 1.5 $\\
Post History&\\
\hline\end{tabularx}\end{center}
\thispagestyle{empty}\pagestyle{empty}
\begin{tipabstract}

This TIP makes the simpler parts of Tcl's Namespace API available to the general C-coding public.
\end{tipabstract}
\tableofcontents\setcounter{page}{0}\clearpage\pagestyle{plain}

\section{Rationale}

Tcl has had namespace support for a number of years now, ever since version 8.0. However, the C API for working with namespaces (as opposed to the script-level [namespace] command) has been hidden inside Tcl's private header files for all that time. This is mainly because of the complexity of some of the interfaces; name resolution is definitely difficult to document.

But about half the API is not so encumbered, being the parts that deal with basic features like creation and destruction of namespaces themselves. It is these simpler parts that this TIP exposes as they have little risk of changing in the future, and I believe they should be made public particularly as it would allow extensions that create commands in namespaces to ensure the existence of the namespace first without resorting to applying \textit{Tcl\_Eval} to a small script.

This TIP does not call for any alteration to the name, signature or behaviour of any API function at all. Note that these functions already have ``public'' names.

\section{Exposed API Functions}

There are the following new public functions (with signatures included for reference only):
\begin{description}
\item[Tcl\_CreateNamespace]
Creates a new namespace.
\begingroup\small\begin{verbatim}
    Tcl_Namespace * Tcl_CreateNamespace(Tcl_Interp *interp, CONST char *name,
	    ClientData clientData, Tcl_NamespaceDeleteProc *deleteProc)
\end{verbatim}
\endgroup
\item[Tcl\_DeleteNamespace]
Deletes an existing namespace.
\begingroup\small\begin{verbatim}
    void Tcl_DeleteNamespace(Tcl_Namespace *nsPtr)
\end{verbatim}
\endgroup
\item[Tcl\_AppendExportList]
Retrieves the export patterns for a namespace.
\begingroup\small\begin{verbatim}
    int Tcl_AppendExportList(Tcl_Interp *interp, Tcl_Namespace *nsPtr,
            Tcl_Obj *objPtr)
\end{verbatim}
\endgroup
\item[Tcl\_Export]
 Set/append to the export patterns for a namespace.
\begingroup\small\begin{verbatim}
    int Tcl_Export(Tcl_Interp *interp, Tcl_Namespace *nsPtr,
            CONST char *pattern, int resetListFirst)
\end{verbatim}
\endgroup
\item[Tcl\_Import]
 Import commands matching a pattern into a namespace.
\begingroup\small\begin{verbatim}
    int Tcl_Import(Tcl_Interp *interp, Tcl_Namespace *nsPtr,
            CONST char *pattern, int allowOverwrite)
\end{verbatim}
\endgroup
\item[Tcl\_ForgetImport]
Remove imports matching a pattern.
\begingroup\small\begin{verbatim}
    int Tcl_ForgetImport(Tcl_Interp *interp, Tcl_Namespace *nsPtr,
            CONST char *pattern)
\end{verbatim}
\endgroup
\item[Tcl\_GetCurrentNamespace]
Retrieve the current namespace.
\begingroup\small\begin{verbatim}
    Tcl_Namespace * Tcl_GetCurrentNamespace(Tcl_Interp *interp)
\end{verbatim}
\endgroup
\item[Tcl\_GetGlobalNamespace]
Retrieve the global namespace.
\begingroup\small\begin{verbatim}
    Tcl_Namespace * Tcl_GetGlobalNamespace(Tcl_Interp *interp)
\end{verbatim}
\endgroup
\item[Tcl\_FindNamespace]
Search for a namespace.
\begingroup\small\begin{verbatim}
    Tcl_Namespace * Tcl_FindNamespace(Tcl_Interp *interp, CONST char *name,
            Tcl_Namespace *contextNsPtr, int flags)
\end{verbatim}
\endgroup
\item[Tcl\_FindCommand]
Search for a command and return its token, optionally in a namespace. Note that command tokens are already returned from \textit{Tcl\_CreateCommand} and \textit{Tcl\_CreateObjCommand} so this is not a new type of result.
\begingroup\small\begin{verbatim}
    Tcl_Command Tcl_FindCommand(Tcl_Interp *interp, CONST char *name,
            Tcl_Namespace *contextNsPtr, int flags)
\end{verbatim}
\endgroup
\item[Tcl\_GetCommandFromObj]
Get a command token given a name.
\begingroup\small\begin{verbatim}
    Tcl_Command Tcl_GetCommandFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr)
\end{verbatim}
\endgroup
\item[Tcl\_GetCommandFullName]
Get the full name of a command from its token.
\begingroup\small\begin{verbatim}
    void Tcl_GetCommandFullName(Tcl_Interp *interp, Tcl_Command command,
            Tcl_Obj *objPtr)
\end{verbatim}
\endgroup
\end{description}

Each of these functions will be declared in future within \textit{tcl.decls} (with the entries in \textit{tclInt.decls} deprecated) and will also be documented.

\section{Copyright}

This document is placed in the public domain.

\section{Colophon}

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