Closed gootik closed 7 years ago
0 is a valid number much like 1,2,3 or -13.37. Why should this singular number be false?
Because it indicates false. In c, c++, java and many other languages it is false.
I know that, but this is "our" language we can form it with our own rationale. What is the reasoning that lox should treat 0 as false but not negative numbers or empty strings?
Ouch, this was a total oversight on my part. I'd originally documented Lox's truthiness rules in chapter 3. But I cut it out to keep the chapter shorter with the intention of moving it to chapter 9 ("Control Flow"). I forgot that it actually comes into play before that in "Evaluating Expressions".
Oops! I moved the chunk of prose into 7 explaining what truthiness means and what Lox's rules for it are and why. (Mainly, it follows Ruby and its simple.)
Sounds good, I wasn't aware this is how Ruby handles truthiness. Thanks.
It just seems weird to me that Lox treats
!0
asfalse
.