On Nov 28, 2007 7:38 PM, Vasiljevic Zoran <[EMAIL PROTECTED]> wrote: > > On Nov 28, 2007, at 8:14 PM, Stephen Deasey wrote: > > > > > {$bool == 1} is not a valid test of truthiness. > > ... so Tcl and C are "broken"?
Tcl and C are fine. The example is broken. For example, in C the above should be: if (bool != 0) { printf("truth"); } because 1 is not the only value of true. Same in Tcl, although it's not sufficient because integers other than 0 are not the only valid representation of truth. The *default* representation of truth is the integer 1: % expr 1 < 2 1 % expr 2 < 1 0 You can certainly use 1/0 for true/false. But if you only check the equality of a boolean against 1 you are only checking a small subset of integers, and none of the other truths: yes, y, t, on, etc. Therefore, I don't think it's fair to say that this is a more robust test of Tcl truth: if {$bool == 1} ... > When Tcl disallows us to use 1/0 for true/false and test on 1/0 equality for > it, then we can talk more about it. It is already disallowed... :-) if: http://www.tcl.tk/man/tcl8.5/TclCmd/if.htm The if command evaluates expr1 as an expression (in the same way that expr evaluates its argument). The value of the expression must be a boolean (a numeric value, where 0 is false and anything is true, or a string value such as true or yes for true and false or no for false) expr: http://www.tcl.tk/man/tcl8.5/TclCmd/expr.htm A Tcl expression consists of a combination of operands, operators, and parentheses... Where possible, operands are interpreted as integer values... If no numeric interpretation is possible (note that all literal operands that are not numeric or boolean must be quoted with either braces or with double quotes), then an operand is left as a string (and only a limited set of operators may be applied to it). Operands may be specified in any of the following ways: [1] As a numeric value, either integer or floating-point. [2] As a boolean value, using any form understood by string is boolean. [...] string is ...: http://www.tcl.tk/man/tcl8.5/TclCmd/string.htm#M16 Returns 1 if string is a valid member of the specified character class, otherwise returns 0. If -strict is specified, then an empty string returns 0, otherwise an empty string will return 1 on any class. string is boolean: Any of the forms allowed to Tcl_GetBoolean. Tcl_GetBoolean: http://www.tcl.tk/man/tcl8.5/TclLib/GetInt.htm Tcl_GetBoolean expects src to specify a boolean value. If src is any of 0, false, no, or off, then Tcl_GetBoolean stores a zero value at *boolPtr. If src is any of 1, true, yes, or on, then 1 is stored at *boolPtr. Any of these values may be abbreviated, and upper-case spellings are also acceptable. ------------------------------------------------------------------------- SF.Net email is sponsored by: The Future of Linux Business White Paper from Novell. From the desktop to the data center, Linux is going mainstream. Let it simplify your IT future. http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4 _______________________________________________ naviserver-devel mailing list naviserver-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/naviserver-devel