Oh, and both versions of your code worked for me. Check that you copied just the function part, with no extra/missing parens.
--Leif
--
You received this message because you are subscribed to the Google Groups "4Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to 4clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You’re welcome. Here are the exact parts of your solution I put in the text area:
;; parens cleaned up a bit
#(loop [zz %2 maap {}]
(if (= () zz)
maap
(recur (rest zz) (merge maap {(first zz) %1}))))
;; also works
(fn [defy keyz]
(loop [zz keyz maap {}]
(if (= () zz)
maap
(recur (rest zz) (merge maap {(first zz) defy})))))
Here’s a translation of a loop/recur
to reduce
:
(loop [m {}, ks [:a :b :c]]
(if (seq ks)
(recur (assoc m (first ks) (first ks)) (next ks))
m))
;; -->
(reduce (fn [m k] (assoc m k k)) {} [:a :b :c])
Hope that helps,
Leif