This is very cool and intressting. I have to think about something to do with core.async.<p>This is also a good example why macros are just awesome. Go is a language design to work well with goroutins and channels, but the clojure code looks just as good and readable. You could simply not have such idiomatic use of these concepts without macros.<p>Or am I wrong, can a flexible language like scala or python be extended to look as good for that usecase? I dont know enougth of the tricks scala people use, I cant juge if it is possible.
Are the first two examples equivalent? In the go version, an anonymous function is being declared and then called with the value of the outer 'i'. In the clojure version, it appears that the value of 'i' is part of the closure for that function.<p>The go version does what it does to avoid a race condition, because the goroutines are being spun up in the background and it's highly likely that it will take longer to spin up at least one of them than it will to finish the loop, so without it you'd likely get output of all nines.<p>If the clojure version doesn't have that problem, then I think it's a somewhat telling indication of how it's actually working.<p>TL/DR: The Go version has to work around the race condition because the runtime is doing things "right", is core.async?
Are the clojure threads actually lightweight? Thread/sleep is blocking so you'd need to occupy 10 threads right? If you wanted to sleep without blocking a real thread would you use an executor service to write to a channel after delay and block on that?
Small bug irrelevant to the main point of the article:
The very last golang example has a leak. If the timeout does occur, main will exit after a timeout and the spawned go routine will hang on the channel push.<p>I think the easiest fix is to make the channel buffered.
"make(chan string)" => "make(chan string, 1)"
Not sure if there is a more idiomatic golang way to accomplish this.
Quick question for anyone here familiar with core.async:<p>Would it be possible (and if so what would be the simplest way) to implement something like Python's generators and `yield` statement in Clojure using core.async? I'm thinking something like:<p><pre><code> (defn range [n]
(generator
(loop [i 0]
(yield i)
(when (< i n)
(recur (inc i)))
(let [generator (range 5)]
(generator) ;; => 0
(generator) ;; => 1
;; etc
)</code></pre>
This is pretty awesome. I'm waiting on a clojure book in the mail, but this article makes me want to dive in sooner!<p>Being a Go fan, this definitely draws me to clojure as a language since the other language I've been messing with was racket (a scheme lisp).
In Go, am I supposed to seed the rand manually? <a href="http://i.imgur.com/Rw5afx9.png" rel="nofollow">http://i.imgur.com/Rw5afx9.png</a>