创建无限循环的惯用方法是什么?
while(true){
calc();
}
我想永远调用 calc 函数。只有一个函数被一遍又一遍地调用。
编辑: 我忘记提及的另一件事是 calc 有副作用。它执行一些计算并修改字节数组。
最佳答案
while
位于核心库中。
(while true (calc))
这扩展为一个简单的recur
。
(defmacro while
"Repeatedly executes body while test expression is true. Presumes
some side-effect will cause test to become false/nil. Returns nil"
[test & body]
`(loop []
(when ~test
~@body
(recur))))
关于Clojure无限循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1515103/