TIP #292: ALLOW UNQUOTED STRINGS IN EXPRESSIONS ================================================= Version: $Revision: 1.3 $ Author: Brian Griffin State: Draft Type: Project Tcl-Version: 8.7 Vote: Pending Created: Wednesday, 01 November 2006 URL: https://tip.tcl-lang.org292.html Post-History: ------------------------------------------------------------------------- ABSTRACT ========== This TIP proposes allowing unquoted words to be recognized as strings in expressions (*expr*, *if*, *while*). RATIONALE =========== Currently the following fails with a syntax error: set foo bar expr {$foo eq bar} This seems antithetical to the EIAS Tao of Tcl. The *set* command does not require the quotes, so why should *expr*, especially since the operands of the *eq* and *ne* operators are treated as strings. It also seems reasonable for the *==* and *!=* 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 *==* 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: 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]} { ... } but I must: if {$var eq "ENUM_VALUE_ONE"} { ... } 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. PROPOSED CHANGE ================= Change the expression parser to accept unquoted words that are not function names as strings. Modify /EqualityExpr/ to reject unqoted strings for "*==*", but allow them for "*eq*". DRAFT IMPLEMENTATION ====================== None, at the moment. COPYRIGHT =========== This document has been placed in the public domain. ------------------------------------------------------------------------- TIP AutoGenerator - written by Donal K. Fellows