On Mar 22, 2:34 pm, Frantisek Sodomka <fsodo...@gmail.com> wrote: > (defn f [#^Double x] (+ x 2)) => #'user/f > (f 3) => 5 > (f nil) => java.lang.NullPointerException (NO_SOURCE_FILE:0) > ; why NPE?
nil is Java null. The Clojure "+" function eventually compiles to Java "+", which throws an exception on null. > (f 2/3) => 8/3 > ; why not an error that argument isn't java.lang.Double? The type tag is just a hint, not a constraint. This might be an error in ahead-of-time compiled Clojure, but not at the REPL. > (f "a") => java.lang.ClassCastException: java.lang.String cannot be > cast to java.lang.Number (NO_SOURCE_FILE:0) > ; wants java.lang.Number, but I was hinting for java.lang.Double As above, the type tag is not a constraint. But "+" needs a number, and that *is* a constraint. -Stuart Sierra --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---