-- Shakespeare, A Midsummer Night's Dream
Act V, Scene I, Line 152
Often in programming (and life) you do not get exactly what you want. Say we have a simple function which adds numbers together. How should the input be structure? Should we require the caller to place all the values into some type of collection? Why can't the caller pass in the values one at a time into the function?
Say we want the following:
We would like to be able to call our summer function with a variable number of arguments but we want to be able to work with the arguments like they were in a collection. This is were splatting comes into play.
How would we do something like this in Clojure?
We see in Clojure we can destruct the parameters using the & to obtain the rest of the parameters, in the case of summer & values will give us everything the function is called with. We can then apply this collection against the + function using apply. Apply allows use to pass in a collection as the last argument to a function which does not take collections.
In Clojure we do not need a summer function since that is exactly how the + function works.