Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: b10c851a4313a0bb6aafc543b12233a800a19905
Ticket: 218232ffffffffffffffffffffffffffffffffff
patch to enhance expr expression syntax
User & Date: nobody on 2000-10-26 00:54:52
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    OriginalBugID: 2669 RFE
    Version: 8.2
    SubmitDate: '1999-08-31'
    LastModified: '1999-09-15'
    Severity: SER
    Status: Closed
    Submitter: techsupp
    ChangedBy: hobbs
    OS: Linux-Red Hat
    Machine: Other
    FixedDate: '2000-10-25'
    ClosedDate: '1999-09-15'
    
    
    Name:
    
    Roger E Critchlow Jr
    
    
    
    DesiredBehavior:
    
    Make the expr command use conventional variable reference and function
    
        call syntax
    
        for references to Tcl scalar variables and calls to Tcl commands and
    
        procedures in
    
        addition to the Tcl macro/command substitution currently implemented.
    
        Hence,
    
        {expr a} would return the value of the Tcl variable named "a" or report
    
        "can't read "a":
    
        no such variable", rather than throwing a syntax error, and {expr
    
        f(1,2,3)} would
    
        return the result of calling [f 1 2 3] or report "invalid command name:
    
        "f"", rather than
    
        throwing an undefined math function error.  The expr parser is enhanced
    
        to accept
    
        identifiers which include the namespace delimiter.   The existing expr
    
        syntax is
    
        unaffected by this enhancement, and existing programs which do not
    
        depend on
    
        syntax errors or undefined math function errors will continue to work
    
        without 
    
        modification.
    
        
    
        For instance, the factorial function currently written as:
    
        
    
        proc factorial {n} { expr {$n>1 ? $n*[factorial [expr {$n-1}]] : 1} }
    
        
    
        can be written in the enhanced expr as simply:
    
        
    
        proc factorial {n} { expr n >1 ? n*factorial(n-1) : 1} }
    
        
    
        eliminating two quotations, three dollars, and a nested call to expr.
    
        It's
    
        not only easier to read and write, it evaluates more efficiently
    
        because
    
        nested calls to expr are no longer needed to pass computed arguments.
    
        
    
        Calls to Tcl commands which take a variable name as an argument need
    
        to quote the variable name if written in enhanced expr syntax.
    
        
    
        set a 2; expr set(a,3)
    
        
    
        creates a variable named "2" with the value "3",  but
    
        
    
        expr set({a},3)
    
        
    
        sets the value of "a" to "3". 
    
        
    
        Array references through the enhanced expr can be done by writing a
    
        function call to the array name with array index(es) as argument(s) and
    
        supplying a Tcl procedure of the same name which constructs a Tcl array
    
        reference.  This isn't the greatest solution, but it at least allows
    
        references
    
        to computed array indexes, eg a(i+1), without nested calls to expr.
    
        
    
        The patches to implement this enhancement come to 294 lines in diff -r
    
        -c format, confined to tclParseExpr.c and tclCompExpr.c
    
    
    
    Patch:
    
    http://www.elf.org/pub/tcl8.2.0-expr.patch
    
    
    
    PatchFiles:
    
    tclCompExpr.c
    
        tclParseExpr.c
    
    
    
    
    
    The newsgroup pointed out several compatability with this idea. 
    -- 09/15/1999 hobbs
    
  4. foundin changed to: "obsolete: 8.2"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "nobody"
  9. subsystem changed to: "69. Other"
  10. title changed to: "patch to enhance expr expression syntax"
  11. type changed to: "RFE"