Re: How to dynamically pass operators to if?

Andrew Falanga writes:
if { $val1 $oper $val2 } {

Donald Arseneau wrote:
This used to work, long ago, but the round of expansion done by
[expr] (and its equivalents) was changed to perform substitution
of operands only, not operations or other syntax.

Can you say more about when that was?

At least as long as I've been using Tcl, the [expr] parser wants
operators present in the argument in order to determine the
structure of the expression. See this from version 7.4:

% info patch
% set op <
% set x 1
% set y 2
% if {$x $op $y} {puts 1} {puts 2}
syntax error in expression "$x $op $y"

This rule was in place long before it started making a performance
difference in Tcl 8.0.

| Don Porter Mathematical and Computational Sciences Division |
| donald.porter@xxxxxxxx Information Technology Laboratory |
| NIST |

Relevant Pages

  • Re: A bit of tcl advocacy ...
    ... This post compares programming TCL to jumping through flaming hoops. ... The expr factorial example is also discussed in the following patch. ... allows you to avoid syntax entirely and write arithmetic ...
  • Re: About Tcl syntax...
    ... 12 rules of Tcl syntax that would be required to make ... There is a big difference between "Tcl works this way, ... with no exceptions" and "just this one exception". ... Having to use "expr" I ...
  • Script interception and parsing - best way?
    ... the scripts themselves can consist of ordinary TCL ... commands interspersed with commands that are to be passed to a ... So how, if at all, should I go about parsing the script in the first ... seed [expr $z+1] ...
  • Re: C-like structs and scope
    ... > BitMover to add some new syntax to Tcl. ... In OOP systems there is usually no need for struct-alike constructs ... are equally complex to write (I may vote for [$a foo bar] to be honest, ...
  • Re: Dangers of web apps written in Tcl
    ... a little-language (expr) results in one more (unexpected to the ... beginner) round of evaluation than most other languages, ... first time I have to attack a web application written in Tcl I'll be ... Complex web apps typically take hundreds to user inputs and I think it's ...