I have a one-dimensional vector, a vector of indices to update within the vector, and a value which should be associated with each of these indices.
I'm new to Clojure, and imagine that there might be a more idiomatic way to write the routine that I ended up with:
(defn update-indices-with-value [v indices value]
(loop [my-v v
my-indices indices
my-value value]
(if (empty? my-indices)
my-v
(recur (assoc my-v (peek my-indices) my-value)
(pop my-indices)
my-value))))
I know that assoc can be used to update multiple keys or indices within an associative collection, but I couldn't figure out the syntactic magic to use assoc with an arbitrary list of keys or indices.