True is one of the two possible values of a boolean expression.

  1. True values are the case-insensitive words yes, on, true, their unique abbrevations, and non-zero integers,
  2. False values are the case-insensitive words no, off, false, their unique abbrevations, and 0.

The function string is true returns true if its argument obeys the condition 1. above (and string is false does the opposite).

string is true {} and string is false {} are normally both True. To make the empty string False, use string is true -strict {} and string is false -strict {}.

LV: I guess I must be really too old for programming languages, because making a command return a wrong answer to facilitate some other action, in AN EXTENSION, seems just wrong to me.

AM 2007-01-18: If it is any consolation, in mathematics one needs to deal with similar special cases:

  • The sum over zero elements
  • The product over zero elements
  • Quantifiers over the empty set
  • In geometry one usually deals with objects "in general position" to avoid thinking about a bunch of collinear points for instance

It may seem to be a bizarre hack to make some long forgotten program work, and it probably is. But taking care of these nauseating edge cases is a part of life.

LV: Oh, I understand having to have hacks to make things work. But it seems, to me, that making the uniquely strange behavior the exception, rather than the rule, would have been the way to go. So the person writing a highly specific case of a particular kind of widget has to add a special flag... no big deal. Instead, however, everyone who wants this function to work as expected has to add -strict to their invocations.

You can sometimes get into trouble relying on these different forms. For example, in Tk:

pack [checkbutton .cb -variable toggle]
set toggle 1     ;# Works fine.
set toggle true  ;# Clears the checkbox!

You can work around this using checkbutton's -onvalue and -offvalue arguments, but you're still limited to just one recognised value for each state:

pack [checkbutton .cb -variable toggle -onvalue true -offvalue false]
set toggle true  ;# Works fine.
set toggle 1     ;# Clears the checkbox!

The canonical form for true, like in C, is integer 1. To wit:

 % expr 42==42

See Also

magic names