我有一个在Clojure中generate-code
循环中运行的函数while
:
; ...
(with-local-vars [code nil]
(while true
(var-set code (generate-code @code))
(write-to-file @code)
(execute-code @code)))
显然这不是Clojure-esque - 有没有更好的方法来做到这一点而不引入局部变量?
答案 0 :(得分: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)))