Overview
| Artifact ID: | 63df456f614c105f579fc2912ccd0357d22853a1345f48eb6c7260e8bdcd4a77 |
|---|---|
| Ticket: | 1e66ba3d490260713811edff4722fc1bfa1b4547
expr cannot call math functions named eq/ne/in/ni or starting with them (in_range, eq_zero, ...) |
| User & Date: | serhiy.storchaka on 2026-10-17 10:51:11 |
Changes
- cmimetype changed to: "text/x-fossil-wiki"
- comment changed to:
A math function whose name is a word operator, or starts with one followed by a non-letter, cannot be called from <nowiki>[expr]</nowiki>, although mathfunc(n) says that any command defined in <tt>tcl::mathfunc</tt> becomes a function: <verbatim> proc tcl::mathfunc::in_range {x lo hi} {expr {$lo <= $x && $x <= $hi}} proc tcl::mathfunc::eq {x} {return $x} expr {in_range(5, 1, 10)} expr {eq(1)} </verbatim> Both fail with <tt>missing operand</tt>, e.g. <verbatim> missing operand at _@_ in expression "_@_in_range(5, 1, 10)" </verbatim> Expected: <tt>1</tt> and <tt>1</tt>, as for any other function name (<tt>inrange(5, 1, 10)</tt> works). Affected names: <tt>eq</tt>, <tt>ne</tt>, <tt>in</tt>, <tt>ni</tt>, and since 9.0 (TIP 461) also <tt>lt</tt>, <tt>le</tt>, <tt>gt</tt>, <tt>ge</tt>, alone or followed by a digit or an underscore (<tt>in_range</tt>, <tt>eq_zero</tt>, <tt>in1</tt>, <tt>lt_x</tt>, ...). <tt>lt_x(1)</tt> works in 8.6 and fails in 9.0. Cause: <tt>ParseLexeme</tt> in generic/tclCompExpr.c returns <tt>STREQ</tt>, <tt>IN_LIST</tt> etc. whenever the third character is not an ASCII letter, without regard to context; <tt>ParseExpr</tt> only turns a <tt>BAREWORD</tt> followed by <tt>(</tt> into a <tt>FUNCTION</tt>. Two possible fixes: in <tt>ParseExpr</tt>, treat a word operator that appears where an operand is expected and is followed by <tt>(</tt> as a function name (a binary operator is always an error there, so this is unambiguous); and in <tt>ParseLexeme</tt>, do not end the operator at <tt>_</tt> (<nowiki>[expr {$a eq_1}]</nowiki> is an error anyway). Digits are ambiguous, since <nowiki>[expr {$a eq1}]</nowiki> currently means <tt>$a eq 1</tt>. History: [ced7ccb24b] (2005, [1201589fff]) made the old parser accept <tt>eq</tt>, <tt>ne</tt>, <tt>in</tt>, <tt>ni</tt> as function names in operand position. The new parser in 8.5a5 (2006; old parser dropped in [877cacc543]) does not, so no 8.5 or later release has supported it. 8.4.20 rejects <tt>eq(1)</tt> too (<tt>unexpected operator eq</tt>). A similar problem for names starting with a number (<tt>nancy</tt>) was [3401704fff]. - foundin changed to: "8.6.18, 9.0.5, 9.1.0"
- login: "serhiy.storchaka"
- priority changed to: "5 Medium"
- resolution changed to: "None"
- severity changed to: "Minor"
- status changed to: "Open"
- subsystem changed to: "45. Parsing and Eval"
- title changed to:
expr cannot call math functions named eq/ne/in/ni or starting with them (in_range, eq_zero, ...)
- type changed to: "Bug"