Interesting seeing the different solutions to this problem. Seems like a 
good place
to remind people about the plumatic/plumbing Graph library:

(require '[plumbing.core :refer (fnk)])(require '[plumbing.graph :as graph])
(def g {
    :a (fnk [] (:a (remote-req {:a 1 :x 2})))
    :b (fnk [] (remote-req 1))
    :c (fnk [a b] (+ a b))
    :d (fnk [] (remote-req 1))
    :e (fnk [] (remote-req 1))
    :f (fnk [d e] (+ d e))
    :ret (fnk [c f] (+ c f))})
(def g-eager (graph/compile g))(def g-par (graph/par-compile g))(time (into {} 
(g-eager {})));; "Elapsed time: 4005.972714 msecs"(time (into {} (g-par {})));; 
"Elapsed time: 1003.358028 msecs"

I’d say it has an intermediate complexity between a simple macro and the 
libraries
you mentioned. And if you wrote your own “lazy + parallel + caching” graph 
compiler,
you could get a good fraction of the functionality of the libraries you 
mentioned.

Muse and Urania give off a Haskell-y vibe (no surprise) and Graph feels 
more Clojure-y
to me, but they are all interesting projects.

Thanks for the post,
Leif

On Tuesday, November 28, 2017 at 6:58:09 AM UTC-7, Eunmin Kim wrote:

Hi, folks
>
> This is small piece of code that is inspired by haxl, muse(
> https://github.com/kachayev/muse), urania(
> https://github.com/funcool/urania). Not a library.
>
> (defn remote-req [result]
>   (Thread/sleep 1000)
>   result)
>
> (defmacro plet [bindings & body]
>   (let [bents (partition 2 (destructure bindings))
>         smap (into {} (map (fn [[b _]]
>                              [b `(deref ~b)])
>                            bents))
>         bindings (vec (mapcat (fn [[b v]]
>                                 [b `(future ~(postwalk-replace smap v))])
>                               bents))]
>     `(let ~bindings
>        ~@(postwalk-replace smap body))))
>
> (time
>  (let [{:keys [a]} (remote-req {:a 1 :x 2})
>        b (remote-req 1)
>        c (+ a b)
>        d (remote-req 1)
>        e (remote-req 1)
>        f (+ d e)]
>    (+ c f)));; "Elapsed time: 4007.60237 msecs"
>
> (time
>  (plet [{:keys [a]} (remote-req {:a 1 :x 2})
>         b (remote-req 1)
>         c (+ a b)
>         d (remote-req 1)
>         e (remote-req 1)
>         f (+ d e)]
>        (+ c f)));; "Elapsed time: 1003.733416 msecs"
>
>
> https://github.com/eunmin/plet
>
> Thanks!
>
> - Eunmin
>
​

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