我正在努力解决clojure的喜悦,并且想知道_语法在函数参数向量中的作用.
例:
(def available-processors (.availableProcessors (Runtime/getRuntime))) (prn "available processors: " available-processors) (def pool (Executors/newFixedThreadPool (+ 2 available-processors))) (defn dothreads! [func & {thread-count :threads exec-count :times :or {thread-count 1 exec-count 1}}] (dotimes [t thread-count] (.submit pool #(dotimes [_ exec-count] (func)))))@H_404_5@下划线的形式是什么?
#(dotimes [_ exec-count] (func))@H_404_5@
解决方法
我相信,根据惯例,Clojure使用下划线作为所需但未被使用的参数的占位符.正如
Keith Bennet所说:
In Clojure,the underscore is used idiomatically to indicate that the
argument it identifies is not subsequently used.
您的示例与此“使用”一致,因为不需要使用作为索引器的dotime的第一个参数,但表单需要绑定.