语法 – Clojure:[_]在函数参数列表中做什么?
发布时间:2020-12-14 05:11:28 所属栏目:Java 来源:网络整理
导读:我正在努力解决clojure的喜悦,并且想知道_语法在函数参数向量中的作用. 例: (def available-processors (.availableProcessors (Runtime/getRuntime)))(prn "available processors: " available-processors)(def pool (Executors/newFixedThreadPool (+ 2 a
我正在努力解决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))))) 下划线的形式是什么? #(dotimes [_ exec-count] (func)) 解决方法
我相信,根据惯例,Clojure使用下划线作为所需但未被使用的参数的占位符.正如
Keith Bennet所说:
您的示例与此“使用”一致,因为不需要使用作为索引器的dotime的第一个参数,但表单需要绑定. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |