Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 53e3d3bbb14c247f41fa577236343f2bcf36c9dc
Ticket: 217994ffffffffffffffffffffffffffffffffff
Null expressions
User & Date: nobody on 2000-10-26 00:51:47
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    OriginalBugID: 639 Bug
    Version: 8.0
    SubmitDate: '1998-05-25'
    LastModified: '1999-08-14'
    Severity: MED
    Status: Closed
    Submitter: hershey
    ChangedBy: hobbs
    OS: All
    OSVersion: NA
    Machine: NA
    FixedDate: '2000-10-25'
    FixedInVersion: NA
    ClosedDate: '1999-08-14'
    
    
    Consider the following commands in TCL 8.0p2:
    
    % expr 8 + ""
    syntax error in expression "8 + "
    % expr "" + 8
    8
    %
    % expr "" > 10
    syntax error in expression " > 10"
    % if { "" > 10 } { puts true }  else { puts false }
    false
    
    
    Granted, the above code is somewhat strange, but realize that the ""
    could be the return result of any other command such as:
    
    if { [ myCustomCmd arg1 arg2 ] > 10 } { puts true }
    
    
    In general, the fact that TCL does not handle NULL values in its
    expression evaluation causes tremendous headaches.
    
    TCL handles NULL STRINGS such as:
    
    string index "" 9
    
    But returns errors whenever a NULL value is encountered in an
    expression.
    
    Many languages will simply return NULL if an expression
    contains any type of NULL value in it.  It would be very nice if
    TCL would do the same.
    
    I have created a GUI builder that uses TCL as its scripting
    language.  Each field on my screen can have TCL methods associated
    with it.  We have extended TCL to provide a "getfld" and a
    "setfld" command that retrieves/sets the value contained in the field
    on the screen. We would like to simply write code as appears below:
    
    setfld Field1 [ expr [ getfld Field2 ] + [ getfld Field3 ] ]
    
    Unfortunately, we had to create another command called "checkfld"
    that first makes sure the field is not NULL before attempting to
    evaluate the expression:
    
    if { [checkfld Field2 Field3] } {
       setfld Field1 [ expr [ getfld Field2 ] + [ getfld Field3 ] ]
    }
    else {
       setfld Field1 ""
    }
    
    This might not seem too bad but its alot of work to simply add
    2 numbers together and it means that every single time we
    refer to a field on our GUI we need to first make sure its not
    NULL.
    
    We could modify our code to not allow NULL values on our screen
    and force all numeric fields to zero but this would not make a
    very friendly GUI - you need to allow blank numeric fields on
    any GUI.
    
    We have also noticed that the expr "" + 8 command behaves differently
    between TCL 7.3 and TCL 8.0.
    
    So my question is:
    
    Why not change the expr command to return a NULL value when any
    argument in its expression list is NULL?  Other commands that
    take expressions such as "if { expression } " could easily
    be written to make NULL expressions behave the same as FALSE
    expressions.
    
    Thank you for reading this far.  Please let me know if there is
    any hope for this request.
    
    
    Chris Handorf
    602-914-8116
    Motorola SPS
    Phoenix, AZ
    [email protected]
    
    These are programming misunderstandings.  The changes to expr
    are well defined in the porting docs, and expr expressions should
    now always be {}ed for proper evaluation (and speed).
    The error reporting is correct.  For each case:
    
      % expr 8 + ""
      syntax error in expression "8 + "
    
    Here the user receives an error because the binary op + is unsatisfied
    
      % expr "" + 8
      8
    
    Here the user isn't using braces, so the Tcl level of eval converts
    this to just "+ 8", and then expr uses the + as a unary op.
    
      % expr "" > 10
      syntax error in expression " > 10"
    
    > is never a unary op...
    
    % if { "" > 10 } { puts true }  else { puts false }
    false
    
    This works, because the initial use of a string is kicking this
    into the string comparison mode.  A command should not be used
    in this way if it isn't guaranteed what type of arg would be
    received.  Use string compare/equal or fix the command. 
    -- 08/14/1999 hobbs
    
  4. foundin changed to: "obsolete: 8.0"
  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: "Null expressions"
  11. type changed to: "Bug"