TIP #273: ADD TCL_EXPR... SUPPORT TO TCL_GET... FUNCTIONS =========================================================== Version: $Revision: 1.5 $ Author: Carsten Gosvig State: Rejected Type: Project Tcl-Version: 8.5 Vote: Done Created: Wednesday, 30 August 2006 URL: https://tip.tcl-lang.org273.html Post-History: Obsoletes: TIP #176 ------------------------------------------------------------------------- ABSTRACT ========== This TIP proposes adding *Tcl_Expr*... calls to *Tcl_Get*... functions, supporting direct use of expressions for arguments to commands that is defined as int, long, wide-int, double or boolean. RATIONALE =========== Many of Tcl's commands takes an int, long, wide-int, double or boolean as an argument. For list and string commands even in the format of *end-*/N/. However, this is limited to a direct string conversion of the argument to one of the mentioned types, so for even simple expression the *expr* command has to be called explicitly, which is quite cumbersome as can be seen in the following examples: set x [lsearch $list $elem] set new [lrange $list [expr $x-1] [expr $x+1]] set x [string first $string "foo"] set new [string range $string $x [expr [$x+5]] set x [lsearch $list $elem] set hex [format "%X" [expr {$x & 0xFF}]] set file [open $name] set buf [read $file [expr {$len * 2 - 10}]] incr var [expr $step*5+1] after [expr $sec*1000] SPECIFICATION =============== By adding a call to a *Tcl_Expr*... function at the point where the current conversion fails in the *Tcl_Get*... functions (at the label named /bad/ in the current implementation) we will add support for using expressions directly as arguments without needing to go through the *expr* command: set x [lsearch $list $elem] set new [lrange $list $x-1 $x+1] set x [string first $string "foo"] set new [string range $string $x $x+5] set x [lsearch $list $elem] set hex [format "%X" {$x & 0xFF}] set file [open $name] set buf [read $file {$len * 2 - 10}] incr var $step*5+1 after $sec*1000 This TIP does not propose any alterations to any function or procedure signatures. IMPLEMENTATION NOTES ---------------------- The *Tcl_Get* functions needs to be updated with a call to the *Tcl_Expr* functions, and the *Tcl_Get**FromObj* functions need to be updated with a call to the *Tcl_Expr**Obj* functions. COMPATIBILITY --------------- There should be no compability issues, as this TIP only adds functionality to a current error situation. This proposal renders [TIP #176] obsolete, as that describes a solution that is effectively a subset of this TIP. COPYRIGHT =========== This document has been placed in the public domain. ------------------------------------------------------------------------- TIP AutoGenerator - written by Donal K. Fellows