Thank you. Is loop and not for example let, for recursion optimalization?
On Nov 9, 2:51 pm, Stuart Halloway <[email protected]> wrote: > > Hi! > > > I would like to write macro, which tries to evalute one of statements. > > If exception happens the next statement is taken, if not then rest of > > expressions execution is stopped. > > > (defmacro try-this[ & body ] > > `(if (seq ~body) > > (try > > ~(first body) > > (catch Exception e# (try-this ~(rest body)))) > > (throw (Exception. "nothing succeed")))) > > > (try-this > > (/ 2 0) > > (+ 2 3) > > (println "2")) > > > So the macro should expand to something like this: > > > (try > > (/ 2 0) > > (catch Exception e > > (try (+ 2 3) > > (catch Exception e > > (try (println "2") > > (catch Exception e (Exception. "nothing > > succeed"))))))) > > > Any help? > > Something like: > > (defmacro try-this > [& forms] > (loop [[f & more] forms] > (when f > `(try > ~f > (catch Throwable t# > (try-this ~@more)))))) > > Stu > > Stuart Halloway > Clojure/corehttp://clojure.com -- 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
