News for hackers. Stuff that matters.
Re:Lua: Good, bad, and ugly parts by vor_ on Saturday March 09, 2013 @05:04PM (#5349780)
You don't consider it an inconsistency for (1) and (not 0) to evaluate to different results?
Re:Lua: Good, bad, and ugly parts by Stratoscope on Saturday March 09, 2013 @07:55PM (#5350206)
(1) is a number. (not 0) is (false), a boolean. How could they be the same? They must be different because they are different types.
Re:Lua: Good, bad, and ugly parts by vor_ on Saturday March 09, 2013 @08:07PM (#5350238)
Obviously there are reasons for the behavior, but it's still inconsistent to users who are exposed to your scripting API to have:

  if 1 then print "true" end
  if 1 == true then print "never prints" end
Not a reason to avoid the language. But it may be a reason to consider an alternative with more conventional behavior.
Re:Lua: Good, bad, and ugly parts by omaranto on Saturday March 09, 2013 @09:44PM (#5350489)
If you replace 1 with 2 this is an argument against using a vast number of languages, including Squirrel, I think. So maybe you're really saying that languages should forbid non-Boolean values in if statements. Maybe I agree with that.
Re:Lua: Good, bad, and ugly parts by akavi on Saturday March 09, 2013 @06:04PM (#5349943)
Would you consider that an inconsistency if you weren't coming from the C paradigm of 0 == false?
Re:Lua: Good, bad, and ugly parts by vor_ on Saturday March 09, 2013 @07:25PM (#5350132)
Yes, because it's not just a C paradigm. Additionally, even though 1 is true, comparing 1 and true returns false!
Re:Lua: Good, bad, and ugly parts by Stratoscope on Saturday March 09, 2013 @07:58PM (#5350215)
1 is not the same value as true. Just as in the case I commented on a couple of messages above, 1 and true are two different types.

The == operator does not compare the "truthiness" of two values. It compares the values, and if those values are two different types, they are always unequal.

http://www.lua.org/pil/3.2.html

Re:Lua: Good, bad, and ugly parts by vor_ on Saturday March 09, 2013 @08:09PM (#5350246)
I'm aware of the reasons why. It's still inconsistent to users. Remember that Lua is targeted at non-professional programmers.
Re:Lua: Good, bad, and ugly parts by jmaygarden on Saturday March 09, 2013 @08:38PM (#5350332)
In my opinion, having (1==true) evaluated to true, but (2==true) evaluate to false is more inconsistent. Even non-professionals should follow logic if they are going to program.
Re:Lua: Good, bad, and ugly parts by Avshalom on Saturday March 09, 2013 @05:24PM (#5349837)
0 isn't false.
Re:Lua: Good, bad, and ugly parts by vor_ on Saturday March 09, 2013 @07:43PM (#5350179)
It's also not true:

  > if 0 then print "true" end
  true
  > 0 == true
 => false
I know why this is the case. But it's a logical inconsistency for users of the language.
Re:Lua: Good, bad, and ugly parts by ufo on Saturday March 09, 2013 @11:20PM (#5350687)
Stop trolling please. You are advocating for `==` doing type coercion of arguments and that is almost always a misfeature in any language that has that (and the fix usually involves adding an ugly `===` operator after the fact)
Re:Lua: Good, bad, and ugly parts by klibertp on Saturday March 09, 2013 @07:59PM (#5350219)
In the case of Lua rules of what is truthy and why (as I read here) I'd expect (not 0) to be a type error. That's the case in OCaml for example and I think it would be good in Lua.