I am wondering if I’m missing something basic involving vector manipulation. Let’s say I have the following:
(def xs [9 10 11 12 13])
(def idx [0 2])
(def values [1 3])
If I want to return the vector [1 10 3 12 13] in Matlab, I would write xs(idx) = values.
In Clojure, is there a primitive way of achieving this? Right now I’m using the following function:
(defn xinto [seq idx val]
(apply assoc seq (interleave idx val)))
Thanks.
It’s a bit awkward because you’ve split up
idxandvaluesinto two seqs, when they’re conceptually a map of indexes to values. So if you’ll permit me a little creative modification of your data format:If you generate
idxandvaluesin some weird way that it’s not convenient to group them together, you can group them later with(map list idx values)and then use myxintoimplementation with that.