This is my implementation of Clojure’s
assoc-in function. I am looking for tips on making it more idiomatic and in general, better.
(defn my-assoc-in (m (& ks) v) (let (sorted-keys (reverse ks)) (loop (curr-key (first sorted-keys) rem-keys (rest sorted-keys) curr-map (get-in m (reverse rem-keys)) acc-val (assoc curr-map curr-key v)) (if (empty? rem-keys) acc-val (let (next-key (first rem-keys) next-rem (rest rem-keys) next-map (get-in m next-rem) next-val (assoc next-map next-key acc-val)) (recur next-key next-rem next-map next-val))))))