Table of Contents

About

Tcl defines :

  • true as any of 0, false, no, or off
  • false as any of 1, true, yes, y or on

In all case 1 or 0 is stored. These tokens are case insensitive, which means Yes, yes, and YES are the same.

If in the condition clause of an IF statement, TCL has :

  • a string: it try to convert it as an integer 0 and 1. Otherwise, you get an error
  • an integer: it check if the value is 0 otherwise it's true.

Example

True

/> set var 1
1
/> string is true $var
1
/> set var on
on
/> string is true $var
1
/> set var yes
yes
/> string is true $var
1
/> set var y
y
/> string is true $var
1

False

/> set var 0
0
/> string is false $var
1
/> set var off
off
/> string is false $var
1
/> set var no
no
/> string is false $var
1
/> set var n
n
/> string is false $var
1
/> set var false
false
/> string is false $var
1

In an IF statement

If in the condition clause of an IF statement, TCL has :

  • a string: it try to convert it as an integer 0 and 1. Otherwise, you get an error
  • an integer: it check if the value is 0 otherwise it's true.
/> set var -1
-1
/> if {$var} then {puts "true"} else {puts "false"}
true

Documentation / Reference