(let [xs (range 10)] (mapcat (fn [[a b]] [(/ a 2) b]) (partition 2 xs)))
(0 1 1 3 2 5 3 7 4 9)
(let [m {:a 1, :b 2, :c 3, :d 4}] (zipmap (keys m) (vals m)))
{:a 1, :b 2, :c 3, :d 4}
(let [x (atom 3) l (lazy-seq (cons @x nil))] (reset! x 5) (first l))
5(let [x 5 l (- (int (/ 5 2))) r (+ l x)] [l r])
[-2 3]
(let [m ["the" "quick" "brown" "fox"]] (apply (juxt (partial max-key count) (partial min-key count)) m))
["brown" "fox"]
(let [[x y && {:keys [a b]}] [1 2 :a 3 :b 4]] [a b])
[nil nil]
(let [f [+ - *]] (for [y f] {(:name (meta (var y))) (y 1 2)}))
({nil 3} {nil -1} {nil 2})
(let [meta-m (fn [x] (with-meta {x x} {x x}))] (meta (merge (meta-m :foo) (meta-m :bar))))
{:foo :foo}
(let [x (cons (do (println "ein") 1) (cons (do (println "twei") 2) nil))] (first x))
1"ein\ntwei\n"(let [v [1 2 3]] (first (filter #(= 3 (v %)) (range (count v)))))
2(let [m {:a 1, :b 2, :c 3}] (zipmap (keys m) (map inc (vals m))))
{:a 2, :b 3, :c 4}
(let [m {:a 1, :b 2, :c 3}] (zipmap (keys m) (map inc (vals m))))
{:a 2, :b 3, :c 4}
(let [a (into-array [1 2 3]) s (seq a)] (aset a 1 5) s)
(1 5 3)
(defn counter [coll] (let [groups (group-by identity coll)] (zipmap (keys groups) (map count (vals groups)))))
#'user/counter
(let [m {:foo1 "bar1"} cond (= 1 2)] (cond-> m cond (assoc :foo2 "bar2")))
{:foo1 "bar1"}
(let [f (fn [& [a b c]] (println a b c))] (f 4 6 8))
nil"4 6 8\n"(def foo (let [lalala 1] (fn foo [a b c] (println a b c lalala))))
#'user/foo
(let [a {:a (atom 0)}] (= a (do (swap! (:a a) inc) (println a) a)))
true"{:a #object[clojure.lang.Atom 0x703dee58 {:status :ready, :val 1}]}\n"(defmacro hello [[msgs-name] & body] `(fn [& msgs#] (println msgs#) (let [~msgs-name msgs#] ~@body)))
#'user/hello
(let [x [1 2 3 4]] (reduce conj (subvec x 0 3) (subvec x 3)))
[1 2 3 4]
(let [myfn (fn myfn [x] (lazy-seq (cons x (myfn (inc x)))))] (take 5 (myfn 1)))
(1 2 3 4 5)
(let [foo (fn [& [a b :as all]] [a b all])] (foo 1 2 3))
[1 2 (1 2 3)]
(let [m {:a 1} k :b v nil] (into m (when-not (nil? v) [[k v]])))
{:a 1}
(let [f 'inc arg (with-meta '(inc 1) {:x 1})] (meta (second `(~f ~arg))))
{:x 1}
(let [orig {:a 1} new {:a 2, :b 3}] (select-keys (merge orig new) (keys orig)))
{:a 2}
(defn cycler [coll] (let [a (atom (cons nil (cycle coll)))] #(first (swap! a rest))))
#'user/cycler
(let [[answer guesses :as data] [[1 2 3] [4 2 1]]] (apply map = data))
(false true false)
(let [l ["a" "b" "c"]] (str (clojure.string/join " " (pop l)) ": " (peek l)))
"a b: c"(let [a (into-array (range 5)) v (into [] a)] (aset a 0 17) (get v 0))
0(let [a '(1 2) b (cons 0 a) c (rest b)] (identical? a c))
true(let [{:strs [a b c]} {"a" 1, "b" 2, "c" 3}] (+ a b c))
6(let [{:keys [a b & ss]} {:a 1, :b 2, :c 3, :d 4}] ss)
nil(let [v {:bar 1} e ["bar is" :bar]] (map #(get v % %) e))
("bar is" 1)
(let [{:keys [a b], :as m} {:a 1, :b 2, :c 3}] [a b m])
[1 2 {:a 1, :b 2, :c 3}]
(let [x (str "abc") y (str "a" "b" "c")] [(identical? x y) x y])
[false "abc" "abc"]
(let [[x y & z :as all] [1 2 3 4]] [x y z all])
[1 2 (3 4) [1 2 3 4]]
(let [a {:a {:deep :map}} b {:b 1}] [(assoc b :foo (:a a)) b a])
[{:b 1, :foo {:deep :map}} {:b 1} {:a {:deep :map}}]
(let [l ["a" "b" "c"]] (str (clojure.string/join " " (butlast l)) ": " (last l)))
"a b: c"(let [r (fn [pattern] (fn [s] (re-find pattern s)))] ((r #"o hai") "o hai everyone"))
"o hai"(let [s (set {:a 1, :b 2, :c 3, :e 4})] [(keys s) (vals s)])
[(:e :c :b :a) (4 3 2 1)]
(let [funcall (fn [f & args] (apply f args))] [(funcall +) (funcall + 1 2)])
[0 3]
(let [a {} b {}] [(identical? (assoc a :a 1) (assoc a :a 1)) (identical? a b)])
[false true]
(let [m {:a 10, :b 20}] (reduce #(update-in %1 [%2] inc) m (keys m)))
{:a 11, :b 21}
(let [[x y] '(5 6)] ((fn [z a] (+ z a 1)) x y))
12(let [[xs [y & ys]] (split-with (complement #{3}) (range 0 5))] `(~@xs ~@ys))
(0 1 2 4)
(let [v [10 11 12 13 14]] (concat (subvec v 0 5) (subvec v 5)))
(10 11 12 13 14)
(let [a (object-array 5) v (conj (vec a) :end)] (aset a 0 :hi) v)
[nil nil nil nil nil :end]
(let [myseq (take 30 (repeatedly #(rand-int 30)))] (for [x myseq y myseq] [x y]))
([21 21] [21 16] [21 20] [21 16] [21 6] [21 4] [21 5] [21 4] [21 10] [21 20] [21 17] [21 22] [21 19] [21 25] [21 6] [21 17] [21 18] [21 13] [21 29] [21 28] [21 23] [21 25] [21 7] [21 9] [21 21] [21 28] [21 21] [21 16] [21 15] [21 14] [16 21] [16 16] [16 20] [16 16] [16 6] [16 4] [16 5] [16 4] [16 10] [16 20] [16 17] [16 22] [16 19] [16 25] [16 6] [16 17] [16 18] [16 13] [16 29] [16 28] [16 23] [16...
(defmacro dosync-once [& exprs] `(let [retried# (atom false)] (dosync (when @retried# (throw ...)) ~@exprs)))
#'user/dosync-once
(let [f (fn [x & y] (first (drop 1e3 y)))] (apply f (iterate inc 0)))
1001

