为什么不'for'在'go'里面工作?

Ale*_*yev 2 clojure

为什么调用此函数不会打印任何内容?

(defn test-go-loop []
  (go (for [a (cycle [:a :b :c])]
        (do (println a) (<! (timeout 1000))))))
Run Code Online (Sandbox Code Playgroud)

Tay*_*ood 6

for懒惰评估,你的代码中没有任何东西要求结果for.试试doseq:

(defn test-go-loop []
  (go (doseq [a (cycle [:a :b :c])]
        (println a)
        (<! (timeout 1000)))))
Run Code Online (Sandbox Code Playgroud)