Cool! Check out code-walking libraries like riddley 
<https://github.com/ztellman/riddley> or tools.analyzer.jvm 
<https://github.com/clojure/tools.analyzer.jvm>
to properly support special forms and variable shadowing. I had a quick 
crack myself
but gave up when I remembered how hard this problem is.

Thanks,
Ambrose

On Tuesday, November 28, 2017 at 8:58:09 AM UTC-5, 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