Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2011-01-31
19:40 • Ticket [3107983fff] Glitch in the constant expression optimization. status s... artifact: 01c9c381da user: msofer
2010-11-18
04:37 • Ticket [3107983fff]: 4 changes artifact: fe9ad230ca user: dgp
04:25 • Ticket [3107983fff]: 4 changes artifact: 1f64fb00f3 user: ferrieux
03:27 • Ticket [3107983fff]: 4 changes artifact: 7585b31753 user: dgp
03:21 • Ticket [3107983fff]: 4 changes artifact: 6a1dda1c75 user: dgp
2010-11-12
22:56 • Ticket [3107983fff]: 5 changes artifact: 1d297a177f user: avl42
22:55 • Ticket [3107983fff]: 1 change artifact: c4d3de3fe8 user: dgp
22:49 • Ticket [3107983fff]: 4 changes artifact: 18ba239b94 user: avl42
22:44 • Ticket [3107983fff]: 4 changes artifact: 80396953d5 user: ferrieux
22:34 • Ticket [3107983fff]: 4 changes artifact: a2ead95911 user: ferrieux
15:32 • New ticket [3107983fff]. artifact: 3f214dfb0b user: avl42

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.