Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: b814f420ef66022a8a4a2023242acc8ca42a2410
Ticket: 1062849fffffffffffffffffffffffffffffffff
EXPR with single substitution
User & Date: msofer on 2004-11-23 08:37:23
Changes

  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"