Glitch in the constant expression optimization.
Open3107983fffffffffffffffffffffffffffffffffCreated 16 years agoUpdated 16 years ago
Descriptionplain2010-11-12 15:32:45
% proc tcl::mathfunc::foo x { puts "foo:>>>$x<<<"; return $x }
% set x 1; expr {foo($x?" 0x42 ":" 0x41" )}
foo:>>> 0x42 <<<
66
% expr {foo(1?" 0x42 ":" 0x41" )}
foo:>>>66<<<
66
%
If the condition is a constant, then the result of the "?:" operator is numericalized even if it gets passed to an external function.
ferrieuxplain2010-11-12 22:34:54
Analysis at http://groups.google.com/group/comp.lang.tcl/browse_frm/thread/c7888bc3ee8b7ad8/cbe4abc6190e7727#cbe4abc6190e7727
ferrieuxplain2010-11-12 22:44:52
Two possible decisions: (1) stick to the convert-to-numeric spirit, and add extra TryCvtToNumeric on entry to user-provided mathfuncs (2) decide it is over-eager, and keep it only on entry to built-in numerics. Remove it from end-of-expr. I guess (1) is more gentle, as it keeps compatibility. (2) may sound harsh, but it would be more EIAS-ly.
avl42plain2010-11-12 22:49:08
My preference would be for (2).
dgp Ticket [3107983fff]: 1 change
[History diff]2010-11-12 22:55:54
avl42plain2010-11-12 22:56:41
...but that might require a TIP, so the bug-fix probably should only change the particular shortcut-route to not use "expr" for pre-calculation, but perhaps some (for now internal) "expr-without-tryCvtToNumeric".
dgpplain2010-11-18 03:21:50
According to TIP 232,
"The [expr] command shall be modified so that an expression of the form:
f(arg1,arg2,...)
shall generate code equivalent to that generated by
[tcl::mathfunc::f [expr { arg1 }] [expr { arg2 }] ...]
"
This means the constant optimizer case is actually
getting this done as prescribed, and it's the non-constant
case which is buggy.
The mathfunc.n manpage isn't quite as explicit, but suggests
the same thing.
dgpplain2010-11-18 03:27:28
Heh. TIP 232 *also* says: "There is no longer any restriction [on functions] ... that their arguments and results must be numeric." Hoo boy.
ferrieuxplain2010-11-18 04:25:38
Then, the tryCvtToNumeric emitted at the end of each [expr] is ... unwanted ?
dgpplain2010-11-18 04:37:41
I just know the issue of passing strings to/from functions was raised and discussed when the feature was in dev or new, but I cannot find it.
msofer Ticket [3107983fff]: 1 change
[History diff]2011-01-31 19:40:03
Log in (anonymous is fine) to add a comment.