Version 5 of Boolean

Updated 2011-05-02 16:08:43 by oehhar

True or False. Tcl has no separate Boolean type, like in C, the integers 0 (false) and 1 (true - in fact any nonzero integer) are used.

NEM: Although expr will also accept "true" and "false" (and "yes"/"no"..) as Boolean values.

1S In fact, there's no separate Integer type in Tcl as well -- everything is a string. A proper boolean value is either a proper integer, with, like in C, zero meaning false and non-zero meaning true, or one of the following: yes, no, true, false, on, or off.

RS The canonical forms however, like expr produces them, are 1 and 0.

See Boolean Logic or Integers as Boolean Functions.


HaO Since TCL8.5, expr knows the bool() function to bring strings in boolean canonical form. This is quite handy to use == or != on booleans in different form:

% expr {bool(true) == bool(1)}
1

== does not work for arbitrary booleans:

% expr {true == 1}
0

[ Category Glossary ]