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
7.4p3
% set op <
<
% set x 1
1
% set y 2
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 |
| http://math.nist.gov/~DPorter/ NIST |
|______________________________________________________________________|
.