Arrays and collections / Arrays

;; Clojure has no separate "dynamic array": a vector already grows,
;; there is no fixed-size array to grow out of
(def cnt 5)
(def zeros (vec (repeat cnt 0)))

(def numbers (assoc zeros 0 1))
;; numbers is [1 0 0 0 0], zeros is still [0 0 0 0 0]
(println numbers)
(println (conj numbers 2))        ; [1 0 0 0 0 2] — one longer

;; when a real mutable buffer is needed, use a transient
(def built (persistent! (reduce conj! (transient []) (range 5))))
;; built is [0 1 2 3 4]
(println built)