4 ms·
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 partic
by lelf 13y ago
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!
- _halgari 13y agoAs 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.
- Tuna-Fish 13y agoIf you use clojure.typed, I think the second example would give you a compile-time type error.
- tobik 13y agoWhile 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