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?

-- 
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

Reply via email to