omnipaste

Extra features for map destructuring

whoCreated: chouser whenCreated: 2008-04-23 12:12:38 mimetype: text/plain
download   paste more
diff --git a/src/boot.clj b/src/boot.clj
index e4d064e..8c03e7b 100644
--- a/src/boot.clj
+++ b/src/boot.clj
@@ -1908,15 +1908,23 @@ not-every? (comp not every?))
                     (fn [bvec b v]
                       (let [gmap (or (:as b) (gensym "map__"))
                             defaults (:or b)]
-                         (loop [ret (-> bvec (conj gmap) (conj v))
-                                bes (seq (-> b (dissoc :as) (dissoc :or)))]
+                         (loop [ret (-> bvec (conj gmap) (conj (list `or v {})))
+                                bes (reduce
+                                      (fn [bes entry]
+                                          (apply merge
+                                                 (dissoc bes (key entry))
+                                                 (apply hash-map
+                                                        (mapcat (fn [n] [n ((val entry) n)])
+                                                                ((key entry) bes)))))
+                                      (-> b (dissoc :as) (dissoc :or))
+                                      {:keys #(keyword (str %)), :strs str, :syms #(list `quote %)})]
                           (if bes
                             (let [bb (key (first bes))
                                   bk (val (first bes))
                                   has-default (contains? defaults bb)]
                               (recur (pb ret bb (if has-default
                                                   (list `get gmap bk (defaults bb))
-                                                   (list `get gmap bk)))
+                                                   (list gmap bk)))
                                      (rest bes)))
                             ret))))]
                 (cond

omnipaste