Why should I use 'apply' in Clojure?

后端 未结 6 1883
执念已碎
执念已碎 2021-01-30 08:34

This is what Rich Hickey said in one of the blog posts but I don\'t understand the motivation in using apply. Please help.

A big difference between Clojur

6条回答
  •  感动是毒
    2021-01-30 09:16

    apply basically unwraps a sequence and applies the function to them as individual arguments.

    Here is an example:

    (apply + [1 2 3 4 5])
    

    That returns 15. It basically expands to (+ 1 2 3 4 5), instead of (+ [1 2 3 4 5]).

提交回复
热议问题