\documentclass[]{article}
\usepackage{amsmath,graphicx,supertabular,hyperref,tabularx,ifthen}
\title{TIP \#473: Allow a Defined Target Namespace in oo::copy}
\date{June 06, 2017}
\author{Donal 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 \#473}&\textbf{Allow a Defined Target Namespace in oo::copy}\\\hline
Author&

Donal Fellows \tipmail{dkf}{users.sf.net}
\\
Created&Tuesday, \(\text{6}^{\text{th}}\) June 2017\\
Type&Project\\
Tcl Version&\(8.6.7\)\\
State&Final\\
Vote&Done\\
Version&\tipversion$Revision: 1.4 $\\
Keywords&Tcl, missing functionality, bugfix\\
Post History&\\
\hline\end{tabularx}\end{center}
\thispagestyle{empty}\pagestyle{empty}
\begin{tipabstract}

This TIP adds functionality to \textbf{oo::copy} to allow the created copy to have a defined namespace, much as \textbf{oo::class}'s \textbf{createWithNamespace} method allows such a namespace to be given on normal object creation.
\end{tipabstract}
\tableofcontents\setcounter{page}{0}\clearpage\pagestyle{plain}

\section{Rationale}

Due to an oversight, the \textbf{oo::copy} command is missing the ability to have an explicit namespace name specified to use as the instance namespace of the target object. It was always intended to have this (and the functionality is there in the C API), but it was omitted from the Tcl-level interface.

Having this capability allows objects to be used as factories for namespaces, which is in many ways an inversion of the way that TclOO was designed (with namespaces as the basis for objects). It was requested by Nathan Coulter as a way to enable more complex behaviour in Rivet and NaviServer. See Tcl Issue dd3b844fda [\url{http://core.tcl.tk/tcl/tktview/dd3b844fdabdeae5fcb0}] for more information.

\section{Proposed Change}

I propose to add one more optional argument to \textbf{oo::copy}, \textit{targetNamespace}, that if provided and non-empty will be the name of a namespace (resolved relative to the current namespace if not an absolute name) that will be the name of the newly created target object's instance namespace. The named namespace must not already exist. Note that specifying the \textit{targetObject} as the empty string will cause the object's command to be automatically chosen.

\begin{quote}
\textbf{oo::copy} \textit{sourceObject} ?\textit{targetObject}? ?\textit{targetNamespace}?
\end{quote}

The meaning of the result of the command is unchanged.

\section{Implementation}

See the oo-copy-ns branch. [\url{http://core.tcl.tk/tcl/timeline?r=oo-copy-ns}]

\section{Copyright}

This document has been placed in the public domain.

\section{Colophon}

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