Truthiness isn't really type coercion, it's just a convention that conditionals treat everything other than nil or false as true. It allows for doing things
(if blah
then
else)
instead of
(if-not (nil? blah)
then
else)
You are loosing information in the code, but it is something that you can easily adapt to and that doesn't generally introduce errors in clojure.
It's also nice to things like
(or value1 value2 value3)
To get the first non-nil, non-false value in the listed values.
No, it's actually not, because if you look at the definition of the conditionals, you can see that the conditionals have to deal with the cases on their own -- the language does not implicitly convert the type of an object for you.
Clojure is strongly typed, not weakly typed, so it doesn't have type coercions.
1
u/kcuf Jun 12 '16
Truthiness isn't really type coercion, it's just a convention that conditionals treat everything other than nil or false as true. It allows for doing things
instead of
You are loosing information in the code, but it is something that you can easily adapt to and that doesn't generally introduce errors in clojure.
It's also nice to things like
To get the first non-nil, non-false value in the listed values.