(let [{{x :x, y :y} :a} {:a {:x 1, :y 2}}] [x y])
[1 2]
(let [[x y & zs] (range 10)] {:foo x, :bar y, :baz zs})
{:bar 1, :baz (2 3 4 5 6 7 8 9), :foo 0}
(let [s (pr-str {:a 1, :b 2})] (println (type s) (type (read-string s))))
nil"java.lang.String clojure.lang.PersistentArrayMap\n"(let [v [:a :b :c :d] indices [1 3]] (map v indices))
(:b :d)
(defmacro m [n] (let [names (repeatedly n gensym)] `(fn [~@names] (+ ~@names))))
#'user/m
(let [x (fn [& more] (take 5 more))] (apply x (iterate inc 1)))
(1 2 3 4 5)
(let [x [:this :that] k (first x) v (second x)] (list k v))
(:this :that)
(let [a (range 1 12)] (format "%s" (apply str (interleave " " a))))
" 1"(let [{:keys [a b c]} {:a 10, :c 30}] (prn a b c))
nil"10 nil 30\n"(let [coll (range 14)] (for [i (range 3)] (drop i (take-nth 3 coll))))
((0 3 6 9 12) (3 6 9 12) (6 9 12))
(let [{a :a, b :b, :as m, :or {a "a0", b "b0"}} {}] m)
{}(let [f (fn [x y] (- x y))] (+ (f 12 15) 9))
6(let [pow (fn [a b] (reduce * (repeat a b)))] (pow 2 3))
9(let [m {:a 1, :b 2, :c 3}] (zipmap (vals m) (keys m)))
{1 :a, 2 :b, 3 :c}
(let [{a :a, :as m} '(1 2 :a 4)] (println a m))
nil"4 {1 2, :a 4}\n"(defn accumulator [n] (let [acc (atom n)] (fn [i] (swap! acc + i))))
#'user/accumulator
(let [[& [bar & boo :as baz]] [1 2 3]] [bar boo baz])
[1 (2 3) (1 2 3)]
(let [f (fn [& {[a1 a2] :a}] [a1 a2])] (f :a [1 2]))
[1 2]
(let [x (transient {:a 1, :b 2, :c {:d 3}})] (type (:c x)))
clojure.lang.PersistentArrayMap(loop [] (let [read-bytes (rand)] (if (< read-bytes 0.3) nil (do (print \.) (recur)))))
nil".."(let [id2 {:id 2}] (contains? #{{:id 1} {:id 2} {:id 3}} id2))
true(let [a (atom 0) d (delay (swap! a inc))] [@d @d @d])
[1 1 1]
(let [a 1 f (fn [] a) a 2 f2 (fn [] a)] [(f) (f2)])
[1 2]
(let [{a :a, b :b, :as m, :or {a "a0", b "b0"}} {}] a)
"a0"(let [foo (transient {})] (doseq [i (range 15)] (assoc! foo i i)) (persistent! foo))
{0 0, 1 1, 2 2, 3 3, 4 4, 5 5, 6 6, 7 7}
(let [nana (identity Double/NaN)] [(.equals nana nana) (= nana nana) (== nana nana)])
[true true false]
(let [one {:a 1, :b 2} two (assoc one :b 3)] [one two])
[{:a 1, :b 2} {:a 1, :b 3}]
(let [foo [[1 2] [2 3]]] (reduce #(conj %1 (last %2)) foo))
[1 2 3]
(let [anon (fn f [i] (when-not (zero? i) (f (dec i))))] (anon 4))
nil(let [{foo :foo, bar :bar, :or {bar (+ foo 10)}} {:foo 10}] bar)
20(let [things ["cooking" "painting" "sex" "clojure"]] (str "the joy of " (rand-nth things)))
"the joy of sex"(let [a (atom 1) f (swap! a inc)] `(if ~f (~f)))
(if 2 (2))
(defn serialize-bytes [x] (binding [*print-dup* true] (let [s (pr-str x)] (.getBytes s "UTF-8"))))
#'user/serialize-bytes
(let [v []] (do (for [item [1 2 3]] (conj v item)) (println v)))
nil"[]\n"(let [m {:foo 42, :bar 23}] (zipmap (keys m) (map str (vals m))))
{:bar "23", :foo "42"}
(let [x$ 1 x% 2 x* 3 x# 4] [x$ x% x* x#])
[1 2 3 4]
(let [{[a b :as c] :val} {:val [1 2 3]}] [a b c])
[1 2 [1 2 3]]
(let [[west north east south] [0 1 2 3] my-dir west] (prn my-dir))
nil"0\n"(let [c (map (comp resolve symbol) (.split "comp - inc" " "))] c)
(#'clojure.core/comp #'clojure.core/- #'clojure.core/inc)
(let [v [1] split-list (split-at 0 v)] (concat (split-list 0) (next (split-list 1))))
()(let [a (range 1 12)] (format "%s" (apply str (interpose " " a))))
"1 2 3 4 5 6 7 8 9 10 11"(let [pap (partial partial apply) + (pap +)] ((comp + range) 10))
45(defn mr3 [s rf mf] (let [x (reduce rf (map mf s))] x))
#'user/mr3
(let [x 3 y 42] (cond-> x (even? x) inc :else (do y)))
42(let [[a :as [b :as [c :as [d]]]] (range)] [a b c d])
[0 0 0 0]
(let [map {:foo 42, :bar 23}] (zipmap (keys map) (map str (vals map))))
{:bar 23, :foo 42}
(let [a 1 b nil] [(when a (inc a)) (when b (inc b))])
[2 nil]
(let [x 3 l (lazy-seq (cons x nil)) x 5] (first l))
3(defmacro cons-when [x xs] (let [tmp# x] (concat (when tmp# (list tmp#)) xs)))
#'user/cons-when
(let [[n [d]] '(a '(b c d))] {:n n, :d d})
{:d quote, :n a}

