Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 6150e8d61cfd1a34770a3243bbc6c1ef6b738b60
Ticket: 1062849fffffffffffffffffffffffffffffffff
EXPR with single substitution
User & Date: alove on 2004-11-09 04:01:07
Changes

  1. assignee changed to: "dkf"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    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 what is known as "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.)
    
    
  4. foundin changed to: "None"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "alove"
  9. subsystem changed to: "16. Commands A-H"
  10. title changed to: "EXPR with single substitution"
  11. type changed to: "RFE"