philipbohun.com

Glojure by Example: Variadic Functions

A parameter after & collects extra arguments into a sequence. Here those arguments are joined by a separator. Calling the function with no extra arguments yields an empty sequence.

(require '[clojure.string :as string])

(defn join-with [sep & parts]
  (string/join sep parts))

(println (join-with "-" "a" "b" "c"))
(println (pr-str (join-with ", ")))

pr-str shows the empty string with quotes.

$ glj variadic-functions.glj
a-b-c
""

Next example: Closures.