As others have noted, this is pretty much what monads are made for. I've
found Brian Marick's "Functional Programming for the Object-Oriented
Programmer"'s chapter on monads really good at teaching how to recognize
situations where monads would be a good fit.

For this specific use-case, you can probably, as an intermediate solution,
define a fairly simple macro that would get you almost all you want,
something like:

(defmacro mlet
  [bindings & body]
  (if (seq bindings)
    (let [[b expr & r] bindings]
      `(try (let [~b ~expr]
              (mlet ~r ~@body))
            (catch Exception e#
              (let [~b [:mlet/error e#]]
                (let ~(->> r
                           (partition 2)
                           (mapcat (fn [[b _]] [b :mlet/unbound]))
                           vec)
                  ~@body)))))
    `(do ~@body)))
(mlet [a (+ 1 2)
       b (- a 3)
       c (/ 10 b)
       d (inc c)]
  [a b c d]);; => [3 0 [:mlet/error #error {#_elided}] :mlet/unbound]

Depending on how much complexity you're willing to bear within that macro,
you could do smarter things like detecting which variables can still be
computed, etc.

Maybe also take a look at prismatic graph?
https://github.com/plumatic/plumbing

-- 
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/d/optout.

Reply via email to