In this guide, we will discuss Clojure Variadic Functions. Variadic functions are functions that take varying number of arguments (some arguments are optional). Function can also specify the ‘&’ ampersand symbol to take in an arbitrary number of arguments.
Following example shows how this can be achieved.
(defn demo [message & others] (str message (clojure.string/join " " others)))
The above function declaration has the ‘&’ symbol next to the argument others, which means that it can take an arbitrary number of arguments.
If you invoke the above function as
Example
(demo "Hello" "This" "is" "the" "message")
Output
Following will be the output.
“HelloThis is the message”
The ‘clojure.string/join’ is used to combine each individual string argument, which is passed to the function.
Next Topic : Click Here
Pingback: Clojure - Functions with Multiple Arguments | Adglob Infosystem Pvt Ltd
Pingback: Clojure - Functions | Adglob Infosystem Pvt Ltd