Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You don't consider it an inconsistency for (1) and (not 0) to evaluate to different results?


(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.


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.


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.


Would you consider that an inconsistency if you weren't coming from the C paradigm of 0 == false?


Yes, because it's not just a C paradigm. Additionally, even though 1 is true, comparing 1 and true returns false!


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


I'm aware of the reasons why. It's still inconsistent to users. Remember that Lua is targeted at non-professional programmers.


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.


0 isn't false.


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.


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)


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.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: