| Ticket UUID: | 3588512 | ||
| Title: | expr { ( ! true ) == false } | ||
| Type: | Bug | Created on: | 2012-11-19 15:13:07 |
| Submitter: | heinrichmartin | Assigned to: | dgp |
| Subsystem: | 47. Bytecode Compiler | Severity: | |
| Priority: | 5 Medium | Last modified: | 2012-11-20 14:15:21 |
| Status: | Open | Closed by: | |
| Resolution: | None | Closed on: | |
| Version: | current: 8.6.0 | ||
| Description: | ||||
OS: Debian Squeeze
Promblem: expr is not consistent with boolean values and operators, i.e. [expr { ( ! true ) == false }] yields 0
Expected: "not true" is logically the same as "false" - expr should know that.
A few notes:
* tested in tclsh 8.5
* found no bugs for "expr" in current and developement
* a fix could break existing code (that's why I put it in group developement)
* workaround: always use bool() or !! for explicit conversion, i.e. [expr { ( ! true ) == bool ( false ) }] yields 1
| ||||
| User Comments: | ||||
sebres added on 2012-11-20 00:36:09:
This happens because "false" is not the same as boolean "0" (cause of saving it string representation):
% expr { false }
false
% expr { (! true) }
0
So this code is true
% expr { (! true) == 0 }
1
But in something you're right - it is not really consistent, cause:
% expr { false == false }
1
dkf added on 2012-11-20 05:21:34:
Part of the problem is that == isn't really the type of equality you're after; it does _numeric_ equalty and (when that's not type-compatible) otherwise string equality. Alas, '0==false' doesn't fit in that scheme too nicely. This might need to be a FRQ… heinrichmartin added on 2012-11-20 14:15:21:
well, then the documentation is wrong - or at least misleading. expr (==,!=): "Boolean equal and not equal. Each operator produces a zero/one result. Valid for all operand types." btw. why are "expr" and "if" in different bug categories?? another suggestion: is it useful to distinguish '0==false' (1) and '0=="false"' (0)? the parser knows about the boolean meaning of false - otherwise it would raise an invalid bareword exception! So, why is tcl using the string representation of false? | ||||
