Artifacts Associated With Ticket 217994
Ticket change [53e3d3bbb1] (rid 93837) by nobody on 2000-10-26 00:51:47:
- assignee initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized 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 - foundin initialized to: "obsolete: 8.0"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "nobody"
- subsystem initialized to: "69. Other"
- title initialized to: "Null expressions"
- type initialized to: "Bug"
Ticket change [74a00be369] (rid 105236) by welch on 2000-10-26 08:12:10:
- closedate changed to: "2000-10-26T01:12:10"
- closer changed to: "welch"
- priority changed to: "2"
- resolution changed to: "Fixed"
- status changed to: "Closed"
Ticket change [0d490562ee] (rid 114337) by dgp on 2001-04-14 03:46:04:
- closedate changed to: "2001-04-13T20:46:04"
- closer changed to: "dgp"
- foundin changed to: "obsolete: 8.0p2"
- resolution changed to: "Invalid"
- subsystem changed to: "16. Commands A-H"