True is a boolean
value. It is recognised by expr
- True values are yes, on, true, their unique abbrevations, and non-zero integers,
- False values are no, off, false, their unique abbrevations, and the integer 0.
The function string is true
returns true if its argument obeys the condition 1. above (and string is false
does the opposite).
Unless the -strict
flag is passed both [string is true ""]
and [string is false ""]
(i.e., testing the empty string) return 1. This is the case to facilitate entry validation in Tk.
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
(18 january 2007) 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.
The canonical form for true, like in C, is integer 1. To wit:
% expr 42==42
See also: Boolean
, magic names