Hi, On Mar 8, 2:59 pm, Luka <luka.stojano...@gmail.com> wrote:
> (defn leafs [m] > (loop [vs (vals m), accum []] > (if (empty? vs) > accum > (let [v (first vs)] > (if (map? v) > (recur (rest vs) (into accum (leafs v))) > (recur (rest vs) (conj accum v))))))) How about this? (defn leafs [m] (reduce (fn [ls v] (if (map? v) (into ls (leafs v)) (conj ls v))) [] (vals m))) > (defn dissoc-in [m v] > (let [len (count v) > cur (get-in m v)] > (cond > (nil? cur) m > (= len 0) m > (= len 1) (dissoc m (first v)) > true (update-in m (butlast v) #(dissoc % (last v)))))) This is broken. Just because get-in does return nil, does not mean the key is not present. The value could be nil. Hence contains? might return true. How about this? (defn dissoc-in [m ks] (let [path (butlast ks)] (if (get-in m path) (update-in m path dissoc (last ks)) m)))) Sincerely Meikel -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en