Allow Unquoted Strings in ExpressionsBrian Griffin$Revision: 1.3 $Tcl expr
This TIP proposes allowing unquoted words to be recognized as strings in expressions (expr, if, while).
Currently the following fails with a syntax error:
ICAgIHNldCBmb28gYmFyICAgIGV4cHIgeyRmb28gZXEgYmFyfQ==
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:
ICAgICAgICBzZXQgdmFyIEVOVU1fVkFMVUVfT05FICAgICAgICBzd2l0Y2ggJHZhciB7ICAgICAgICAgICAgICAgIEVOVU1fVkFMVUVfWkVSTyB7IC4uLiB9ICAgICAgICAgICAgICAgIEVOVU1fVkFMVUVfT05FICB7IC4uLiB9ICAgICAgICAgICAgICAgIGRlZmF1bHQgeyAuLi4gfQ==ICAgICAgICB9ICAgICAgICBpZiB7W2xzZWFyY2ggJHN1cHBsaWVkX3ZhbHVlcyBFTlVNX1ZBTFVFX09ORV0gPj0gMH0geyAuLi4gfQ==ICAgICAgICBpZiB7W3N0cmluZyBlcXVhbHMgJHZhciBFTlVNX1ZBTFVFX09ORV19IHsgLi4uIH0=
but I must:
ICAgICAgICBpZiB7JHZhciBlcSAiRU5VTV9WQUxVRV9PTkUifSB7IC4uLiB9
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.
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".
This document has been placed in the public domain.