Every so often I find myself wanting to apply a collection of functions on several collections of parameters. It\'s easy to do with map and a very simple function.
(map #(%1 %2 %3 %4) [- + *][1 2 3][1 2 3][1 2 3])
(-1 6 27)
The problem is that if you want to allow a variable number of arguments, the & syntax puts the values in a vector, necessitating the use of apply. Your solution looks fine to me but as Brandon H points out, you can shorten it to #(apply %1 %&)
.
As the other answerers have noted, it has nothing to do with funcall
which I think is used in other Lisps to avoid ambiguity between symbols and functions (note that I called the function as (%1 ...)
here, not (funcall %1 ...)
.