user=> (macroexpand '(with-open [x A y Y] do stuff here)) (let* [x A] (try (clojure.core/with-open [y Y] do stuff here) (finally (. x clojure.core/close)))) user=>
with-open expands to a (try (finally (.close ...))) On Sun, Sep 13, 2009 at 7:38 PM, Richard Newman <holyg...@gmail.com> wrote: > >> Clojure does not seem to support iteration inside catch or finally >> forms. > > Apparently not directly. Splitting the iteration into a separate named > function works, though: > > (defn print-seq [foo] > (doseq [x foo] > (println x))) > > (let [foo (atom [1 2 3])] > (try > (throw (new Exception "foo")) > (catch Exception e > (print-seq @foo)))) > > > so you could try > > (defn close-all-files [files] > (doseq [file files] > (.close file))) > > (let [files (atom [])] > (try > (open-my-many-files files) > ;; the files atom now refers to a vector of open file handles > (do-dangerous-io @files) > (finally > (close-all-files @files)))) > > -R > > > > -- And what is good, Phaedrus, And what is not good— Need we ask anyone to tell us these things? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---