2

我有在 Clojuregenerate-code中循环运行的函数:while

; ...
(with-local-vars [code nil]
    (while true
        (var-set code (generate-code @code))
        (write-to-file @code)
        (execute-code @code)))

显然这不是很像 Clojure 式的——有没有更好的方法来做到这一点而不引入局部变量?

4

1 回答 1

6

您可能正在寻找let

(let [code (generate-code)]
    (write-to-file code)
    (execute-code code))

你也可以

((fn [code] 
    (write-to-file code)
    (execute-code code))
 (generate-code))

或者,如果你想

(last ((juxt write-to-file execute-code) (generate-code)))
于 2013-02-17T21:22:45.357 回答