Destructure maps using sets |
||
| whoCreated: chouser | whenCreated: 2008-04-22 13:19:55 | mimetype: text/plain |
| download paste more | ||
diff --git a/src/boot.clj b/src/boot.clj
index e4d064e..1b9f966 100644
--- a/src/boot.clj
+++ b/src/boot.clj
@@ -1918,11 +1918,27 @@ not-every? (comp not every?))
(list `get gmap bk (defaults bb))
(list `get gmap bk)))
(rest bes)))
+ ret))))
+ pset
+ (fn [bvec b v]
+ (let [gmap (gensym "map__")]
+ (loop [ret (-> bvec (conj gmap) (conj (list 'or v '(hash-set))))
+ bs (seq b)]
+ (if bs
+ (let [fb (first bs)
+ s (cond
+ (keyword? fb) (symbol (name fb))
+ (string? fb) (symbol fb)
+ (symbol? fb) fb
+ :else (throw (new Exception (str "Unsupported binding form in set: " fb))))]
+ (recur (-> ret (conj s) (conj (list gmap (list 'quote fb))))
+ (rest bs)))
ret))))]
(cond
(symbol? b) (-> bvec (conj b) (conj v))
(vector? b) (pvec bvec b v)
(map? b) (pmap bvec b v)
+ (instance? clojure.lang.IPersistentSet b) (pset bvec b v)
:else (throw (new Exception (str "Unsupported binding form: " b))))))
process-entry (fn [bvec b] (pb bvec (key b) (val b)))]
(if (every? symbol? (keys bmap))