diff options
author | Rich Hickey <richhickey@gmail.com> | 2008-04-27 17:11:20 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2008-04-27 17:11:20 +0000 |
commit | 000a3068a9e24d6f1a2464390fdecb4241133f45 (patch) | |
tree | ad54a945095dc59122418cbf1da9f3fb27ed4688 | |
parent | 5e9f2b293b307aa7953cd390360d24549e542b92 (diff) |
added :keys, :syms, and :strs support to map/set destructuring, from Chouser
-rw-r--r-- | src/boot.clj | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/boot.clj b/src/boot.clj index e4d064e4..4738c9d5 100644 --- a/src/boot.clj +++ b/src/boot.clj @@ -1908,15 +1908,21 @@ 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] + (reduce #(assoc %1 %2 ((val entry) %2)) + (dissoc bes (key entry)) + ((key entry) bes))) + (dissoc b :as :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 |