Skip to content
Tcl Source Code History Of Ticket 1062849fffffffffffffffffffffffffffffffff
Login

History Of Ticket 1062849fffffffffffffffffffffffffffffffff

Artifacts Associated With Ticket 1062849fffffffffffffffffffffffffffffffff

  1. Ticket change [6150e8d61c] (rid 92223) by alove on 2004-11-09 04:01:07:

    1. assignee initialized to: "dkf"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized 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 initialized to: "None"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. status initialized to: "Open"
    8. submitter initialized to: "alove"
    9. subsystem initialized to: "16. Commands A-H"
    10. title initialized to: "EXPR with single substitution"
    11. type initialized to: "RFE"
  2. Ticket change [ae874f6409] (rid 101654) by dkf on 2004-11-09 17:31:38:

    1. closedate changed to: "2004-11-09T10:31:38"
    2. closer changed to: "dkf"
    3. icomment:
      Logged In: YES 
      user_id=79902
      
      Absolutely categorically no.
      
      This was how [expr] behaved in Tcl 8.0a1, and it was
      specifically changed to the current behaviour on the grounds
      that the community *hated* having commands that had magical
      syntactic relationships with the Tcl parser.  It was about
      the only time the team at Sunlabs (as they were then) got a
      full-blown flaming on comp.lang.tcl if memory serves me
      right. I might not be a complete stranger to controversy,
      but I know when to stay clear of something... :^)
      
      
    4. login: "dkf"
    5. mimetype: "text/plain"
    6. resolution changed to: "Rejected"
    7. status changed to: "Closed"
    8. username: "dkf"
  3. Ticket change [66b12e1fbd] (rid 102762) by dkf on 2004-11-09 17:35:30:

    1. icomment:
      Logged In: YES 
      user_id=79902
      
      Workaround in your case above: create a little [sum] command :)
      
      create line [sum $a 2] [sum $a2 7] \
          [sum $a $bh -2] [sum $b2 $a 3]
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  4. Ticket change [b814f420ef] (rid 128911) by msofer on 2004-11-23 08:37:23:

    1. icomment:
      Logged In: YES 
      user_id=148712
      
      The basic functioning of Tcl is described in Tcl.n as:
         1. the parser substitutes the words in the command line
         2. the first word in the substituted line is called as a
      command, with the remaining words as arguments. The command
      may interpret its arguments in any way it chooses.
      
      This is true for every Tcl command - whether built-in, or a
      proc, or a C-coded extension command. In a sense, this *is*
      what Tcl is.
      
      Thus, the substitution by the Tcl eval-loop cannot be
      avoided without destroying Tcl's simplicity - ie, without
      making xp the sole Tcl command that fails to satisfy the
      Endekalogue. That is a no-no, and is what Donal was alluding
      to. "Skipping the Tcl parser" is beyond the means of a
      command - the parser does its work before noticing what the
      command is. Think of what should happen for eg
         set cmd xp
         set a [$cmd $a*2]
      Start parsing/substituting, and stop when you notice it is
      actually xp?
      
      Your examples were all typed without spaces - ie, it seems
      that you propose an xp that takes a single argument. The
      choice is either that
         set x [xp $a + $a * $b ].0
      errors out (after being parsed to determine the number of
      arguments to xp), or else the Tcl parser has to get a new
      rule that says "if the command name is xp, the rest of the
      command will be passed as a single string argument to xp";
      but you still have to parse to look for the closing ']' -
      so, no real savings.
      
      In summary: in order to work as proposed, xp would have to
      destroy Tcl's simplicity. And it would still fail to be as
      fast as 
      expr {...}.
      
      
    2. login: "msofer"
    3. mimetype: "text/plain"
    4. username: "msofer"