(let [{{{{:keys [blum]} :bloom, :as bloom} :blerg, :as blerg} :blah, :as blah} {:blah {:blerg {:bloom {:blum 'abc}}}}] [blum bloom blerg blah])
[abc {:bloom {:blum abc}} {:blerg {:bloom {:blum abc}}} {:blah {:blerg {:bloom {:blum abc}}}}]
(pr-str (let [[a b] (split-with (partial not= 3) [5 4 3 2 1 2 3 4 5])] (concat a (rest b))))
"(5 4 2 1 2 3 4 5)"(let [m1 {:foo 1, :bar 2, :baz 3} m2 {:foo 4, :bar 5}] (merge (zipmap (keys m1) (repeat nil)) m2))
{:bar 5, :baz nil, :foo 4}
(let [m1 '{a 1, b 2, c 3} m2 '{b 2, d 4, c 3}] (filter m1 (keys m2)))
(b c)
(let [f (fn [pre cur next] [pre cur next]) cl [1]] (map f (cons nil cl) cl (concat (next cl) [nil])))
([nil 1 nil])
(let [[_ e-class e-name & e-ret :as catch-clause] '(catch Exception _ x)] `(catch ~e-class ~e-name (do (println ~e-name) ~e-ret)))
(catch Exception _ (do (clojure.core/println _) (x)))
(let [f #(compare (:x %1) (:x %2))] (= (sorted-map-by f {:x 1, :name "dan"} 1) {{:x 1, :name "juan"} 1}))
false(let [x (range) x+1 (drop 1 x) x+2 (drop 2 x)] (map #(nth % 5) [x x+1 x+2]))
(5 6 7)
(let [m {:foo 0, :bar 2} v '[a b c]] (into {} (map #(vector % (v (m %))) (keys m))))
{:bar c, :foo a}
(let [m [{:foo "zeta"} {:foo "grammar"} {:foo "zalpha"}]] (apply max-key #(read-string (clojure.string/replace (format "36r%-10s" (:foo %)) " " "0")) m))
{:foo "zeta"}
(let [{{:keys [a b c], :as p} :p, :as r} {:p {:a 1, :b 2, :c 3}}] [a b c r])
[1 2 3 {:p {:a 1, :b 2, :c 3}}]
(let [a (atom 0) f (fn [x] (swap! a + x)) g (fn [] (println "a =" @a))] (g) (f 10) (g))
nil"a = 0\na = 10\n"(let [hashm (hash-map 1 2 3 4)] (persistent! (reduce-kv (fn [m k v] (assoc! m k v)) (transient (empty hashm)) hashm)))
{1 2, 3 4}
(let [vec-order (zipmap [:b :a :c] (range))] (into (sorted-map-by #(< (vec-order %1) (vec-order %2))) {:a 1, :b 5, :c 6}))
{:a 1, :b 5, :c 6}
(defn trans-map [f m] (let [t (transient m)] (doseq [k (keys m)] (assoc! t k (f (get t k)))) (persistent! t)))
#'user/trans-map
(count (let [s "***" n 7 spaces (repeat (/ (- n (count s)) 2) \space)] (apply str (concat spaces s spaces))))
7(let [x [:a :b :c :d :e]] (mapv vector x (map (comp vec drop-last) (range (count x) 0 -1) (repeat x))))
[[:a []] [:b [:a]] [:c [:a :b]] [:d [:a :b :c]] [:e [:a :b :c :d]]]
(let [l '(1 2 3 4 5)] (for [i l] (map #(if (not (= % i)) % nil) l)))
((nil 2 3 4 5) (1 nil 3 4 5) (1 2 nil 4 5) (1 2 3 nil 5) (1 2 3 4 nil))
(let [xs [3 2 1]] (mapcat (fn [[x idx]] (for [y (range x)] (assoc xs idx y))) (map vector xs (range))))
([0 2 1] [1 2 1] [2 2 1] [3 0 1] [3 1 1] [3 2 0])
(let [m {:width 3, :height 2, :f vector}] (for [y (range (:height m)) x (range (:width m))] ((:f m) x y)))
([0 0] [1 0] [2 0] [0 1] [1 1] [2 1])
(let [pop-peek (juxt pop peek) stack [1 2] [stack arg1] (pop-peek stack) [stack arg2] (pop-peek stack)] (conj stack (+ arg1 arg2)))
[3]
(let [Length 20 Pad \- Name (vec "TEttinger")] (apply str (map #(or (get Name %1) %2) (range) (repeat Length Pad))))
"TEttinger-----------"(let [a [1 2] b [3 4 5 6]] (concat (interleave a b) (drop (count a) b) (drop (count b) a)))
(1 3 2 4 5 6)
(apply str (map #(apply str %) (let [newlines-every-second-element (comp (partial interpose "\n") (partial partition 2))] (newlines-every-second-element ["a" "b" "c" "d"]))))
"ab\ncd"(let [items (map vector (iterate inc 0) [:a :b :c :d])] (some (fn [[i v]] (if (= v :c) i)) items))
2(let [r 255 g 255 b 255] (-> (bit-or r -16777216) (bit-or (bit-shift-left g 8)) (bit-or (bit-shift-left b 16))))
-1(let [{{:strs [from to]} :form-params} {:form-params {"from" "from-val", "to" "to-val"}}] (str "From is " from ", and to is " to))
"From is from-val, and to is to-val"(let [inds [0 3 4 9] intervals (map - (rest inds) inds)] (mapcat #(cons 1 (repeat (dec %) 0)) intervals))
(1 0 0 1 1 0 0 0 0)
(let [well-behaved? (fn [ob] (= ob (read-string (binding [*print-dup* true] (pr-str ob)))))] (map well-behaved? ['tommy nil false 388 :what (symbol "388")]))
(true true true true true false)
(let [keywordize (fn [m] (into (empty m) (for [[key val] m] [(keyword key) val])))] (keywordize {'some-symbol 1, "some-string" 2, 'symbol.with/namespace 3}))
{:some-string 2, :some-symbol 1, :symbol.with/namespace 3}
(defn my-subs [st from end] (let [f (if (neg? from) (max (+ (count st) from) 0) from)] (subs st f end)))
#'user/my-subs
(let [f #(compare (:x %1) (:x %2))] (= {{:x 1, :name "juan"} 1} (sorted-map-by f {:x 1, :name "dan"} 1)))
true(let [fib (memoize (fn fib [n] (if (<= n 1) n (+ (fib (dec n)) (fib (- n 2))))))] (fib 20))
6765(defn foo [a b c & keyargs] (let [{:keys [d e f]} (apply hash-map keyargs)] [a b c d e f]))
#'user/foo
(apply merge (for [[k v] (partition 2 ["a_b_c" 1 "d" 2])] (let [ks (map keyword (.split k "_"))] (assoc-in {} ks v))))
{:a {:b {:c 1}}, :d 2}
(let [evens (iterate #(+ 2 %) 0) odds (iterate #(+ 2 %) 1)] (take 20 (concat evens odds)))
(0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38)
(let [a {:a 0, :b 1, :c 2} b {:b 3, :c :4, :d 5, :e 6}] (select-keys b (keys a)))
{:b 3, :c :4}
(let [keywordify (fn [m] (if (map? m) (into {} (map (fn [[k v]] [(keyword k) v] m)) m)))] (keywordify {"foo" {"bar" 12}}))
{"foo" {"bar" 12}}
(let [nana Double/NaN] [(.equals nana nana) (= nana nana) (== nana nana) (.equals Double/NaN Double/NaN) (= Double/NaN Double/NaN) (== Double/NaN Double/NaN)])
[true true false true false false]
(let [m1 {:a 1, :b 2} m2 {:b 2, :d 4}] (clojure.set/project [m1 m2] (clojure.set/intersection (set (keys m1)) (set (keys m2)))))
#{{:b 2}}
(let [l [{:key "a", :val "a"} {:key "b", :val "b"} {:key "c", :val "c"}]] (for [a l b l] [a b]))
([{:key "a", :val "a"} {:key "a", :val "a"}] [{:key "a", :val "a"} {:key "b", :val "b"}] [{:key "a", :val "a"} {:key "c", :val "c"}] [{:key "b", :val "b"} {:key "a", :val "a"}] [{:key "b", :val "b"} {:key "b", :val "b"}] [{:key "b", :val "b"} {:key "c", :val "c"}] [{:key "c", :val "c"} {:key "a", :val "a"}] [{:key "c", :val "c"} {:key "b", :val "b"}] [{:key "c", :val "c"} {:key "c", :val "c"}])
(let [a 23] (doseq [b (range 24)] (print (mod (+ (min (- a b) (- b a)) 24) 24) " ")))
nil"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 0 "(let [days-of-christmas (range 12 0 -1) total-presents (reduce #(+ % (apply + %2)) 0 (take-while seq (iterate rest days-of-christmas)))] total-presents)
364(let [square (fn [x] (* x x)) sum-squares (fn [& a] (apply + (map square a)))] (sum-squares 1 2 3 4))
30(defmacro implicitly-bind [[keys-to-bind s] & body] `(let [~@(mapcat (fn [key] (vector key (list (keyword (str key)) s))) keys-to-bind)] ~@body))
#'user/implicitly-bind
(let [{{:keys [a b]} :c, :keys [d e]} {:c {:a 0, :b 1}, :d 2, :e 3}] [a b d e])
[0 1 2 3]
(let [{a :alpha, :keys [b c d], :as all} {:alpha 1, :b 2, :x 3}] [a b c d all])
[1 2 nil nil {:alpha 1, :b 2, :x 3}]
(let [f (fn [n m] (conj (->> n range (partition (int (/ n m))) (map first) vec) n))] (f 100 3))
[0 33 66 100]
(let [v (with-meta [1 2] {:foo :bar})] (map #(meta %) [v (conj v 3) (map identity v) (subvec v 1)]))
({:foo :bar} {:foo :bar} nil nil)
(let [v [1 5 3 3 2 4 5 5 4 5 1 2 1 2 3 5]] (partition-by identity v))
((1) (5) (3 3) (2) (4) (5 5) (4) (5) (1) (2) (1) (2) (3) (5))

