\documentclass[]{article}
\usepackage{amsmath,graphicx,supertabular,hyperref,tabularx,ifthen}
\title{TIP \#272: String and List Reversal Operations}
\date{August 23, 2006}
\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 \#272}&\textbf{String and List Reversal Operations}\\\hline
Author&

Donal K. Fellows \tipmail{donal.k.fellows}{manchester.ac.uk}
\\
Created&Wednesday, \(\text{23}^{\text{rd}}\) August 2006\\
Type&Project\\
Tcl Version&\(8.5\)\\
State&Final\\
Vote&Done\\
Version&\tipversion$Revision: 1.4 $\\
Keywords&Tcl, lreverse\\
Post History&\\
\hline\end{tabularx}\end{center}
\thispagestyle{empty}\pagestyle{empty}
\begin{tipabstract}

This TIP proposes adding commands to reverse the order of characters in strings and elements in lists.
\end{tipabstract}
\tableofcontents\setcounter{page}{0}\clearpage\pagestyle{plain}

\section{Rationale}

According to a recent thread on \url{news:comp.lang.tcl} [\url{http://groups.google.com/group/comp.lang.tcl/browse_frm/thread/a0b8c98c00a31ffc}], there are a number of use cases for reversing strings and lists. While it has always been possible to write Tcl code to do this, it has typically been a fairly inefficient operation, and for some algorithms (admittedly including ones that are benchmarked when comparing Tcl to other languages) this can be the source of a painful slowdown. By putting an efficient implementation in the Tcl core, we will speed up quite a bit of code, more than I originally anticipated it seems; this will make us look better to programmers without much experience with the language too.

\section{Proposed Change}

I propose to add two commands, \textbf{lreverse} to reverse the order of items in a list, and \textbf{string reverse} (a subcommand of \textbf{string}) to reverse the order of characters in a string. I do not propose to provide any C-level API for performing these operations.

\subsection{The lreverse Command}

This shall have the following syntax:

\begin{quote}
\textbf{lreverse} \textit{list}
\end{quote}

It shall return a list that is the same as the input list but with the elements in reverse order.

\subsection{The reverse Subcommand of the string Command}

This shall have the following syntax:

\begin{quote}
\textbf{string reverse} \textit{string}
\end{quote}

It shall return a string that is the same as the input string but with the characters in reverse order. (Note that it shall also return a byte array when the input is a byte array.)

\section{Copyright}

This document has been placed in the public domain.

\section{Colophon}

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