5 ms·
I don't like "1" equal to 1 in Tcl :-/ % expr {"a" eq "b"} 0 % expr {1 eq 1} 1 % expr {1 eq "1"} 1
by ytch 9y ago
I don't like "1" equal to 1 in Tcl :-/
% expr {"a" eq "b"}
0
% expr {1 eq 1}
1
% expr {1 eq "1"}
1
- blacksqr 9y agoWell, since "eq" is explicitly a string comparison operator in Tcl, use of it forces each argument to be evaluated as a string. Given that, what result would make more sense to you?
- ytch 9y agoIt's not problem of 'eq': % expr {1 == "1"} 1
- deleted 9y ago[deleted]
- blacksqr 9y agoPlaying around a bit with tio.run-- Javascript: console.log("1"==1) True Perl: print "1"==1; 1 What's your preferred language?
- blacksqr 9y agoPHP: <?php echo "1"==1; ?> 1
- ytch 9y agoMost of my work use Python right now Python 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> "1"==1 False I don't even notice so many script language has "1"==1, that's interesting. I also find that in Javascript: >>typeof(1) "number" >>typeof("1") "string" PHP: >>> gettype("1") => "string" >>> gettype(1) => "integer" Can distinguish this two type, but AFAIK, I can't do this in Tcl?
- mypalmike 9y agoA major reason Java programs are generally quite robust IMO... System.out.println(1 == "1"); error: incomparable types: int and String
- Animats 9y agoEverything is a string in TCL. It's "scripting languages, the early years."