\documentclass[]{article}
\usepackage{amsmath,graphicx,supertabular,hyperref,tabularx,ifthen}
\title{TIP \#292: Allow Unquoted Strings in Expressions}
\date{November 01, 2006}
\author{Brian Griffin}
\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 \#292}&\textbf{Allow Unquoted Strings in Expressions}\\\hline
Author&

Brian Griffin \tipmail{bgriffin}{model.com}
\\
Created&Wednesday, \(\text{1}^{\text{st}}\) November 2006\\
Type&Project\\
Tcl Version&\(8.7\)\\
State&Draft\\
Vote&Pending\\
Version&\tipversion$Revision: 1.3 $\\
Keywords&Tcl, expr\\
Post History&\\
\hline\end{tabularx}\end{center}
\thispagestyle{empty}\pagestyle{empty}
\begin{tipabstract}

This TIP proposes allowing unquoted words to be recognized as strings in expressions (\textbf{expr}, \textbf{if}, \textbf{while}).
\end{tipabstract}
\tableofcontents\setcounter{page}{0}\clearpage\pagestyle{plain}

\section{Rationale}

Currently the following fails with a syntax error:
\begingroup\small\begin{verbatim}
    set foo bar
    expr {$foo eq bar}
\end{verbatim}
\endgroup

This seems antithetical to the EIAS Tao of Tcl. The \textbf{set} command does not require the quotes, so why should \textbf{expr}, especially since the operands of the \textbf{eq} and \textbf{ne} operators are treated as strings. It also seems reasonable for the \textbf{==} and \textbf{!=} operators to reject unquoted strings as not a valid operand. This provides some enforcement for numerical vs. string comparison by forcing the use of quotes to convert the numeric \textbf{==} to a string equality test.

The rationale for making such a change is it will make complex code a bit easier to read. For example, I can:
\begingroup\small\begin{verbatim}
        set var ENUM_VALUE_ONE

        switch $var {
                ENUM_VALUE_ZERO { ... }
                ENUM_VALUE_ONE  { ... }
                default { ... }
        }

        if {[lsearch $supplied_values ENUM_VALUE_ONE] >= 0} { ... }

        if {[string equals $var ENUM_VALUE_ONE]} { ... }
\end{verbatim}
\endgroup

but I must:
\begingroup\small\begin{verbatim}
        if {$var eq "ENUM_VALUE_ONE"} { ... }
\end{verbatim}
\endgroup

which could lead someone reading the code to incorrectly conclude that ENUM\_VALUE\_ONE is not the same thing as ``ENUM\_VALUE\_ONE'' or miss the fact that they are the same, especially when using a syntax highlighting editor.

\section{Proposed Change}

Change the expression parser to accept unquoted words that are not function names as strings. Modify \textit{EqualityExpr} to reject unqoted strings for ``\textbf{==}'', but allow them for ``\textbf{eq}''.

\section{Draft Implementation}

None, at the moment.

\section{Copyright}

This document has been placed in the public domain.

\section{Colophon}

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