Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2005-11-02
00:17 • Ticket [818100ffff] not all equal booleans are equivalent status still Close... artifact: fe39e5c88f user: dgp
00:17 • Closed ticket [818100ffff]. artifact: ee97306ab8 user: dgp
2004-12-10
00:53 • Ticket [818100ffff]: 1 change artifact: 0eb5ff47d0 user: dgp
2003-11-13
07:21 • Ticket [818100ffff]: 1 change artifact: 4b735c520e user: dgp
07:08 • Ticket [818100ffff]: 4 changes artifact: 66a2e58243 user: dkf
07:08 • Ticket [818100ffff]: 1 change artifact: 029ed43a10 user: dkf
05:51 • Ticket [818100ffff]: 1 change artifact: 9db744fb0a user: dgp
2003-10-06
20:30 • Ticket [818100ffff]: 1 change artifact: fda5b1b11f user: dkf
20:25 • Ticket [818100ffff]: 4 changes artifact: 60046726a7 user: dkf
20:25 • Ticket [818100ffff]: 1 change artifact: 612a147410 user: dkf
20:25 • Ticket [818100ffff]: 1 change artifact: b4f6f32f91 user: dkf
20:25 • Ticket [818100ffff]: 3 changes artifact: 23dfa6fe51 user: dkf
20:25 • Open ticket [818100ffff]. artifact: b8639d07c6 user: dkf
06:32 • Ticket [818100ffff]: 4 changes artifact: 7c9f15ee56 user: mistachkin
06:32 • Pending ticket [818100ffff]. artifact: fc3f7166cc user: mistachkin
06:07 • Ticket [818100ffff]: 2 changes artifact: 71734d3177 user: dkf
06:07 • Closed ticket [818100ffff]. artifact: d75614f4b5 user: dkf
2003-10-05
13:13 • New ticket [818100ffff]. artifact: 1efbe8f4f5 user: nobody

not all equal booleans are equivalent

Closed / Out of Date818100ffffffffffffffffffffffffffffffffffCreated 23 years agoUpdated 21 years ago
Descriptionplain2003-10-05 13:13:16
% expr {(0 == false) ? [puts true] : [puts "you're
screwed"]}
you're screwed

miguelGeorge: let me check for an explanation, 5'
miguelYep, seems to be a bug: the code of INST_EQ does
not attempt a boolean conversion, it compares as
numbers or strings only.
dkfplain2003-10-06 06:07:51
Logged In: YES 
user_id=79902

It's not clear to me whether 0 and false should be equal in
the context of the == operator.  Indeed, == is defined (as
are many other [expr] operators) to operate on
preferentially numbers, and otherwise strings.  In terms of
that, "false" is not numeric, and "0" is a clearly different
string.

IMO it's not a bug.  Just a misreading of the manual by the
person submitting.
dkf Ticket [818100ffff]: 2 changes [History diff]2003-10-06 06:07:52
mistachkin Pending ticket [818100ffff]. [History diff]2003-10-06 06:32:13
mistachkinplain2003-10-06 06:32:14
Logged In: YES 
user_id=113501

In my opinion, we need a TIP to add a math func "bool()" 
which attempts to perform boolean conversion on it's 
argument.

bool(true) == 1
bool(false) == 0
bool(yes) == 1
bool(no) == 0
bool(<any-non-zero-value>) == 1
bool(<any-zero-value>) == 0

This would make expr more complete.
dkf Open ticket [818100ffff]. [History diff]2003-10-06 20:25:38
dkf Ticket [818100ffff]: 3 changes [History diff]2003-10-06 20:25:41
dkf Ticket [818100ffff]: 1 change [History diff]2003-10-06 20:25:42
dkf Ticket [818100ffff]: 1 change [History diff]2003-10-06 20:25:43
dkfplain2003-10-06 20:25:44
Logged In: YES 
user_id=79902

If you (or anyone else) want to write the TIP, feel free.

I'd be tempted to make anything not recognized by
Tcl_GetBooleanFromObj() an error when fed to bool(), just as
int("some string") is illegal too.
dkf Ticket [818100ffff]: 1 change [History diff]2003-10-06 20:30:20
dgp Ticket [818100ffff]: 1 change [History diff]2003-11-13 05:51:11
dkf Ticket [818100ffff]: 1 change [History diff]2003-11-13 07:08:10
dkfplain2003-11-13 07:08:11
Logged In: YES 
user_id=79902

I'm not going to do anything about this on my own; the
current behaviour is exactly as documented and not a bug. 
It's up to someone else as far as I'm concerned.

A workaround is to use !!, like this:
  expr {(!!0 == !!false) ? [puts Cool!] : [puts D'oh!]}
dgp Ticket [818100ffff]: 1 change [History diff]2003-11-13 07:21:45
dgp Ticket [818100ffff]: 1 change [History diff]2004-12-10 00:53:06
dgp Closed ticket [818100ffff]. [History diff]2005-11-02 00:17:44
dgpplain2005-11-02 00:17:45
Logged In: YES 
user_id=80530


TIP 182 resolved this issue.
Log in (anonymous is fine) to add a comment.