On Tue, Dec 15, 2009 at 1:08 AM, Greg Harman <[email protected]> wrote:
> Actually, the for didn't work for me either but I believe that was a
> lazy evaluation issue. The doseq seems to use internal recursion,
> which breaks the try/finally. My final solution was to build up doseq
> functionality with reduce. See below:
>
> (defn foo1 []
> (try
> (println "body")
> (finally
> (doseq [x (range 3)] (println x)))))
>
> (defn foo2 []
> (try
> (println "body")
> (finally
> (for [x (range 3)] (println x)))))
>
> (defn foo3 []
> (try
> (println "body")
> (finally
> (reduce (fn [y x] (println x)) () (range 3)))))
>
> - The foo1 definition can't be evaluated b/c of
> java.lang.UnsupportedOperationException: Cannot recur from catch/
> finally
Simply moving the body of the 'finally' to a fn syntactically
outside the 'finally' clause itself should always work without
having to reimplement the body itself:
(defn foo-fn []
(let [f #(doseq [x (range 3)]
(println x))]
(try (println "body")
(finally (f)))))
--Chouser
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en