Hi, On Aug 10, 8:36 am, Brian Stiles <brian.sti...@gmail.com> wrote:
> The following succeeds: > > (try > (prn 1) > (finally > (prn 2) > (doto (System/out) (.print "-") (.println "-")))) > > prints: > > 1 > 2 > -- > > The following fails (note the odd duplication of "2" in the output): > > (try > (prn 1) > (finally > (prn 2) > (.. (System/out) (print "-") (println "-")))) > > prints: > > 1 > 2 > -2 > -Exception in thread "main" java.lang.NullPointerException Of course it fails, because print is a void method and hence "returns" nil. So you are calling print on nil leading to the NPE. Why the 2 is printed twice... good question: user=> (try (prn 1) (finally (prn 2) (.foo nil))) 1 2 2 java.lang.NullPointerException (NO_SOURCE_FILE:0) user=> (let [] (try (prn 1) (finally (prn 2) (.foo nil)))) 1 2 2 java.lang.NullPointerException (NO_SOURCE_FILE:0) user=> (let [a (atom 2)] (try (prn 1) (finally (prn @a) (.foo nil)))) 1 2 java.lang.NullPointerException (NO_SOURCE_FILE:0) user=> (def a (atom 2)) #'user/a user=> (try (prn 1) (finally (prn @a) (.foo nil))) 1 2 2 java.lang.NullPointerException (NO_SOURCE_FILE:0) Sincerely Meikel -- 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 Note that posts from new members are moderated - please be patient with your first post. 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