Skip to content

Comment on Clojure to die forparent

Comments

Well, there is no such simple interoperability with java from haskell, that's for sure. But otherwise…

  user> (:key nil)
  nil
Mmmm, I'm not certain I particularly want this
  user> (nil :key)
  CompilerException java.lang.IllegalArgumentException: Can't call nil
RUN!

As many are saying it's a pragmatic choice. And it allows you to do stuff like this:

  (:foo (:bar {}))
Without throwing a NPE. Which is what I want 99.9% of the time. As someone who codes in Clojure close to 10 hours a day, I rarely see a problem like you describe.

If you use clojure.typed, I think the second example would give you a compile-time type error.

While true, the second example already gives you a compile-time error in normal Clojure (note the CompilerException). It never compiled and was never evaluated. This on the other hand compiles and is likely what the OP wanted to show:

  user> (let [e nil] (e :key))

  NullPointerException
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.