Skip to content
Tcl Source Code View Ticket
Login

View Ticket

EXPR single substitution

Deleted1064135fffffffffffffffffffffffffffffffffCreated 22 years agoUpdated 22 years ago
Descriptionplain2004-11-10 21:33:29
Note: if you are going to delete this, please email me at 
[email protected] and let me know why.  Thanks.

SUMMARY: The EXPR command in its regular form 
performs two substitutions: one by the Tcl parser and 
one by the EXPR command itself.  But in practice, the 
TCL parser is rarely needed; almost all EXPR commands 
are coded with double-braces to improve performance.  
This is a main contributor to  "quoting hell" when using 
TCL:

set var [expr {$a*25}]
set speed [expr {($a+$b)/75}]

create line [expr {$a+2}] [expr {$a2+7}] \
[expr {$a+$bh-2}] [expr {$b2+$a+3}] 

Rather than using more quotes to give a single 
substitution and more speed, I propose a new command 
called XP, which is identical to EXPR with double braces.  
Using this command, the above code would look like this:

set var [xp $a*25]
set speed [xp ($a+$b)/75]

create line [xp $a+2] [xp $a2+7] \
[xp $a+$bh-2] [xp $b2+$a+3] 

The third line saves 16 characters of typing, including 
eight double-braces that require the shift key.

IMPLEMENTATION: This command would be identical to 
EXPR except that it would skip the TCL parser.  For 
demonstration, you can simulate the command (but not 
its speed) using

proc xp {a} { eval expr { $a } } 

(This proc works only if you exclude spaces from the 
expression, which is why the above examples have no 
spaces.)
dkfplain2004-11-11 16:36:03
Logged In: YES 
user_id=79902

Duplicate of 1062849
Log in (anonymous is fine) to add a comment.