Syntax – clojure: [] What do you do in the function parameter list?

I'm trying to solve clojure's joy and want to know_ The function of syntax in function parameter vector

Example:

(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)))))

What is the form of underline?

#(dotimes [_ exec-count] (func))

Solution

I believe that by convention, clojure uses underscores as placeholders for required but unused parameters As Keith Bennet said:

Your example is consistent with this "use" because you do not need to use the first parameter of dotime as an indexer, but the form needs to be bound

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>