Hi, @halgari! The JS port actually does have this, just haven't found the 
time to port it back.
But basically we can define something like:

(defn goloop*
>   [f initial-state]
>   (letfn [(recur+ [state]
>             (goloop* f state))]
>     (go
>       (f recur+ initial-state))))
>
>
> (defmacro goloop
>   [[var initial-state] & body]
>   `(goloop* (fn [~'recur+ ~var]
>               ~@body)
>             ~initial-state))
>


 And then use it this way:

repl>
> (def ch (chan))
>
#'functional-core-async.core/ch

 
>
repl> 
>
(goloop [acc 0]
>   (go<! [v ch]
>     (if (not= :NIL v)
>       (recur+ (+ acc v))
>       (println "Count" acc))))
> #object[java.util.concurrent.ArrayBlockingQueue 0x3ddbadf5 "[]"] 
>
 
>
repl> 
>
(go>! [ch 1])
> #object[java.util.concurrent.ArrayBlockingQueue 0x28864bee "[]"]
>
 
>
repl>
> (go>! [ch 4])
> #object[java.util.concurrent.ArrayBlockingQueue 0x5caa5b10 "[]"]
>
 
>
repl>
> (go>! [ch :NIL])
> #object[java.util.concurrent.ArrayBlockingQueue 0x2d40473a "[]"]
> Count 5
>

- Divyansh 

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