Clojure: What does [_] do in a Functions Argument List?

后端 未结 3 545
耶瑟儿~
耶瑟儿~ 2020-12-17 11:12

I am working through the joy of clojure and am wondering what the _ syntax does in a functions argument vector.

Example:

(def available-processors
           


        
3条回答
  •  半阙折子戏
    2020-12-17 11:38

    Nothing special about it, it is just a convention for naming something that you don't care about, but still it is a name and can be used like a normal name.

    (defn hello [_] (+ 1 _))
    (hello 10)
    

    UPDATE

    Doing this:

    (defn hello [a a]  (+ a a))
    

    doesn't produce an error and hence you can use as many _ as you want ;).

    NOTE: The above isn't the case with Scheme or CL... Hmm what was the rational behind it in clojure then???

提交回复
热议问题