Arrays and collections / Arrays

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

(def numbers [2 3 5 7 11 13 17])

;; the first method: reduce walks the vector and builds up the answer
(def s1 (reduce (fn [acc n] (str acc n "; ")) "" numbers))
;; s1 is "2; 3; 5; 7; 11; 13; 17; "
(println s1)

;; the second method: join says the same in one call
(def s2 (str/join "; " numbers))
;; s2 is "2; 3; 5; 7; 11; 13; 17"
(println s2)

;; doseq walks the vector when only a side effect is wanted
(doseq [n numbers]
  (print (str n "; ")))
(println)