Hello all, I'm releasing a small library for using resumable exceptions, aka conditions, in Clojure. Resumable exceptions allow the decision about what kind of response to take to an exception to be made in a separate place (higher up the call stack) from where the actual response itself is taken (generally right at the place where the exception was raised). To use in a leiningen project:
[bwo/conditions "0.1.0"] Code: https://github.com/bwo/conditions/ The test suite contains a translation of this example illustrating conditions in CL <http://c2.com/cgi/wiki?CommonLispConditionSystem>: (defn reciprocal-of [v] (c/rtry (if (== v 0) (slingshot/throw+ {:type :zerodivisionerror}) (/ 1 v)) (c/resume-with [:type :return-zero] _ 0) (c/resume-with [:type :return-value] {v :value} v) (c/resume-with [:type :recalc-with] {v :value} (reciprocal-of v)))) (defn determine-infinity [] (c/rtry (let [result (reciprocal-of 0)] (println "Value:" result) result) (c/resume-with [:type :continue] _ -1))) (defn restarter [n] (c/handle (determine-infinity) (c/catch [:type :zerodivisionerror] _ (c/resume {:type :recalc-with :value n})))) (defn aborter [] (c/handle (determine-infinity) (c/catch [:type :zerodivisionerror] _ (c/abort 0)))) Evaluating "(restarter 5)" prints "1/5" and evaluates to 1/5; evaluating "(aborter)" doesn't print anything ("abort" jumps to the handler) and evaluates to 0. The README and docstrings in core.clj are fairly extensive; comments on any aspect are welcome. -- Ben Wolfson "Human kind has used its intelligence to vary the flavour of drinks, which may be sweet, aromatic, fermented or spirit-based. ... Family and social life also offer numerous other occasions to consume drinks for pleasure." [Larousse, "Drink" entry] -- -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.