@worldsendless Any number but 0 is true. Any list / tuple / set / dictionary / string but the empty one is true.
@worldsendless 0 is false -- it's the only number that is.
I don't know that it's as much compatibility as letting programmers say "if x" rather than "if x != 0", "if data" rather than "if len(data) > 0", etc.
https://www.freecodecamp.org/news/truthy-and-falsy-values-in-python/
@peterdrake as a happy Clojure dev I find myself wondering, why should developers want to write "if x != 0"? Why is it any better than "if x != 'cat'"? And why should language designers treat it specially?
@worldsendless I can't cite any evidence, but it seems like there are many situations where you want to do something only if a value is not zero or empty. Certainly you often want to check if x == null before you try to access x's fields or methods.
@peterdrake
@worldsendless
I use that trick all the time in php. Fixing old code requires some funky workarounds.
@peterdrake @worldsendless And for extra fun classes can have a __bool__ method.
@davep @peterdrake Interesting that in Clojure boolean only exist for interop purposes. Is it really a necessary type?
@peterdrake is zero true for C compatibility?