(vec coll)
Creates a new vector containing the contents of coll. Java arrays will be aliased and should not be modified.
user=> (vec '(1 2 3))
[1 2 3]
user=> (vec [1 2 3])
[1 2 3]
user=> (vec #{1 2 3})
[1 3 2]
user=> (vec {:a 1 :b 2 :c 3})
[[:c 3] [:b 2] [:a 1]]
user=> (vec '())
[]
user=> (vec nil)
[]
;; Warning. If the arg is a Java array, then the returned vector will alias it,
;; and modifying the array will thus modify the vector. To avoid this, do
;; not modify the array after the vec call. One way to guarantee this is to
;; make a copy of the array, call vec on the new array, and then lose all
;; references to the copy so it cannot be accessed in any way.
user=> (def a (to-array (repeat 4 0)))
#'user/a
user=> (seq a)
(0 0 0 0)
user=> (def v (vec a))
#'user/v
user=> v
[0 0 0 0]
;; Now change a, and v changes, too, since they share state.
user=> (aset a 2 -5)
-5
user=> v
[0 0 -5 0]
;; One way to avoid this
user=> (def v (vec (aclone a)))
#'user/v
user=> v
[0 0 -5 0]
user=> (aset a 2 -20)
-20
user=> v
[0 0 -5 0]