In Clojure, a vector is a commonly used data structure that is similar to an array. Unlike arrays in some languages, Clojure vectors are immutable and can grow or shrink in size.
Note that vectors in Clojure are printed in the form [v1 v2 v3 ...] when using println.
To run the program, save it as arrays_example.clj and use the clj command:
In Clojure, vectors are more flexible than traditional arrays. They can grow dynamically and are immutable, meaning each operation returns a new vector instead of modifying the original. The assoc and assoc-in functions are used to “update” vectors by creating new ones with the specified changes.
For multi-dimensional structures, we use nested vectors. The reduce function is used to iterate over the indices and create the 2D structure, which is a common functional programming approach in Clojure.