try-or, or-try, try-else or else-try?

utilities — cgrand, 8 January 2009 @ 18 h 26 min

I can’t decide which name is best for this macro:

(defmacro try-or
 "Evaluates exprs one at a time, from left to right. If a form returns a 
  value, this value is returned. If a form throws an exception, the next 
  form is evaluated. 
  If the last form throws an exception, the exception isn't caught." 
 ([] nil)
 ([form] form)
 ([form & forms]
   `(try 
      ~form
      (catch Exception e#
        (try-or ~@forms)))))

6 Comments »

  1. try-cond

    Comment by Shawn — 8 January 2009 @ 23 h 27 min
  2. No, never mind. try-or

    Comment by Shawn — 8 January 2009 @ 23 h 28 min
  3. why not ‘try-one ?

    Comment by lpetit — 21 January 2009 @ 1 h 39 min
  4. It most closely matches the existing function some. So maybe try-some?

    Comment by grayswx — 19 February 2009 @ 9 h 28 min
  5. grayswx: some is a function (plus it takes a predicate), or is a macro. I think try-or is better.

    Comment by Christophe Grand — 23 February 2009 @ 10 h 48 min
  6. try-harder!

    Comment by TheArthur — 16 April 2009 @ 23 h 31 min

RSS feed for comments on this post. TrackBack URI

Leave a comment

(c) 2024 Clojure and me | powered by WordPress with Barecity