\documentclass[]{article}
\usepackage{amsmath,graphicx,supertabular,hyperref,tabularx,ifthen}
\title{TIP \#273: Add Tcl\_Expr... Support to Tcl\_Get... Functions}
\date{August 30, 2006}
\author{Carsten Gosvig}
\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 \#273}&\textbf{Add Tcl\_Expr... Support to Tcl\_Get... Functions}\\\hline
Author&

Carsten Gosvig \tipmail{tcl}{javalite.com}
\\
Created&Wednesday, \(\text{30}^{\text{th}}\) August 2006\\
Type&Project\\
Tcl Version&\(8.5\)\\
State&Rejected\\
Vote&Done\\
Version&\tipversion$Revision: 1.5 $\\
Obsoletes&176\\
Post History&\\
\hline\end{tabularx}\end{center}
\thispagestyle{empty}\pagestyle{empty}
\begin{tipabstract}

This TIP proposes adding \textbf{Tcl\_Expr}... calls to \textbf{Tcl\_Get}... functions, supporting direct use of expressions for arguments to commands that is defined as int, long, wide-int, double or boolean.
\end{tipabstract}
\tableofcontents\setcounter{page}{0}\clearpage\pagestyle{plain}

\section{Rationale}

Many of Tcl's commands takes an int, long, wide-int, double or boolean as an argument. For list and string commands even in the format of \textbf{end-}\textit{N}. However, this is limited to a direct string conversion of the argument to one of the mentioned types, so for even simple expression the \textbf{expr} command has to be called explicitly, which is quite cumbersome as can be seen in the following examples:
\begingroup\small\begin{verbatim}
set x [lsearch $list $elem]
set new [lrange $list [expr $x-1] [expr $x+1]]

set x [string first $string "foo"]
set new [string range $string $x [expr [$x+5]]

set x [lsearch $list $elem]
set hex [format "%X" [expr {$x & 0xFF}]]

set file [open $name]
set buf [read $file [expr {$len * 2 - 10}]]

incr var [expr $step*5+1]
after [expr $sec*1000]
\end{verbatim}
\endgroup

\section{Specification}

By adding a call to a \textbf{Tcl\_Expr}... function at the point where the current conversion fails in the \textbf{Tcl\_Get}... functions (at the label named \textit{bad} in the current implementation) we will add support for using expressions directly as arguments without needing to go through the \textbf{expr} command:
\begingroup\small\begin{verbatim}
set x [lsearch $list $elem]
set new [lrange $list $x-1 $x+1]

set x [string first $string "foo"]
set new [string range $string $x $x+5]

set x [lsearch $list $elem]
set hex [format "%X" {$x & 0xFF}]

set file [open $name]
set buf [read $file {$len * 2 - 10}]

incr var $step*5+1
after $sec*1000
\end{verbatim}
\endgroup

This TIP does not propose any alterations to any function or procedure signatures.

\subsection{Implementation Notes}

The \textbf{Tcl\_Get}\tiplangle{}\textit{Type}\tiprangle{} functions needs to be updated with a call to the \textbf{Tcl\_Expr}\tiplangle{}\textit{Type}\tiprangle{} functions, and the \textbf{Tcl\_Get}\tiplangle{}\textit{Type}\tiprangle{}\textbf{FromObj} functions need to be updated with a call to the \textbf{Tcl\_Expr}\tiplangle{}\textit{Type}\tiprangle{}\textbf{Obj} functions.

\subsection{Compatibility}

There should be no compability issues, as this TIP only adds functionality to a current error situation.

This proposal renders \cite{tip176} obsolete, as that describes a solution that is effectively a subset of this TIP.

\section{Copyright}

This document has been placed in the public domain.

\section{Colophon}

\textit{TIP AutoGenerator --- written by Donal K. Fellows}
\begin{thebibliography}{TIP \#1}
\addcontentsline{toc}{section}{References}
\bibitem[TIP \#176]{tip176}
Damon Courtney,
Don Porter,
Damon Courtney,
\emph{Add String Index Values},
on-line at \url{http://purl.org/tcl/tip/176.html}
\end{thebibliography}
\end{document}
