r/programming • • Jun 11 '16

My Increasing Frustration With Clojure

http://ashtonkemerling.com/blog/2016/06/11/my-increasing-frustration-with-clojure/
176 Upvotes

225 comments sorted by

View all comments

Show parent comments

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

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

0

u/argv_minus_one 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.

That is a type coercion, namely from any type to the Boolean type.

1

u/kcuf Jun 12 '16

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.

Source: https://github.com/clojure/clojure/blob/69136115a8f3246dc5ce3d8eb19ce71e69e42331/src/jvm/clojure/lang/Compiler.java#L2696