I am working through the joy of clojure and am wondering what the _ syntax does in a functions argument vector.
Example:
(def available-processors
The previous answers are good, but since I needed some extra clarification, here's my answer.
(defn blah[_] (str "the value you sent is " _)
is identical to
(defn blah[my-arg] (str "the value you sent is " my-arg)
There is no difference. _ is just a way to let the person looking at the code to know that the parameter is not intended to be used.
So for example, this is fine programatically:
(dotimes [_ 5] (println (str "I'm going to print this 5 times, and this is index # " _)))
But someone looking at the code would think you aren't planning on using the _. So it would be better to use 'n' or 'ind' or whatever, instead of _, just to be clear. If you aren't using that value, like below...
(dotimes [_ 5] (println "I'm going to print this 5 times"))
Then it makes since to bind your parameter to _, as you are indicating that you aren't using it.
And one last thing, if bindings have the same name, the last one wins. So the following will print "4last4last4last4last".
(defn will-print [_ a _ a _ a _ a] (println (str _ a _ a _ a _ a)))
(will-print 1 "a" 2 "b" 3 "c" 4 "last")
So in the println block '_' is bound to 4, and 'a' is bound to 'last'. All of the previous values sent are ignored/overwritten.