Skip to content


kvify now expands into a map-literal.
Browse files Browse the repository at this point in the history
Will now return PersistentHashMap or PersistentArrayMap as
appropriate. Map-literals are emitted as calls to more efficient methods
than clojure.core/hash-map or clojure.core/array-map.
  • Loading branch information
duelinmarkers committed Nov 18, 2014
1 parent 4830b16 commit d0a4bf1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/clojure/jry.clj
Expand Up @@ -95,4 +95,6 @@

(defmacro kvify [& xs]
`(hash-map ~@(interleave (map keyword xs) xs)))
(if (apply distinct? xs)
(zipmap (map keyword xs) xs)
(throw (RuntimeException. (str "duplicate keys to kvify: " xs)))))
3 changes: 2 additions & 1 deletion test/expectations/jry_expectations.clj
Expand Up @@ -62,5 +62,6 @@
(expect false ((k= :one 1 :two 2 :thr 3) {:one 1 :two 1 :thr 3 :x "x"}))
(expect false ((k= :one 1 :two 2 :thr 3) {:one 1 :two 2 :thr 1 :x "x"}))

(expect '(clojure.core/hash-map :a a :b b)
(expect '{:a a :b b}
(expanding (kvify a b)))
(expect RuntimeException (macroexpand-1 '(jry/kvify a a a a)))

0 comments on commit d0a4bf1

Please sign in to comment.