(defmacro spy [expr] `(let [v# ~expr] (println '~expr "is" v#) v#))
#'user/spy
(let [myinc (fn [x] (+ 1 x))] (map myinc [1 2 3]))
(2 3 4)
(let [[f & r] (drop 281 (vals (ns-publics 'clojure.core)))] (remove f r))
()(defmacro my-let [vecx & body] `(let ~(vec (rest vecx)) ~@body))
#'user/my-let
(let [s "q1w2e" r #"\d+"] (interleave (clojure.string/split s r) (re-seq r s)))
("q" "1" "w" "2")
(defn print-all [body] (let [result (do body)] (binding [*print-length* nil] (print result))))
#'user/print-all
(let [{:keys [foo bar], :or {foo 5}} (list :bar 2)] [foo bar])
[5 2]
(defmacro m1 [x] `(let [f# (fn [y#] (inc y#))] (f# ~x)))
#'user/m1
(defmacro with-data [v body] `(fn with-data# [d#] (let [~v d#] ~@body)))
#'user/with-data
(let [add (fn [x] (fn [y] (+ x y)))] ((add 1) 2))
3(let [[x & xs] '(1 2 3) y (last xs)] y)
3(let [teams (range 1 9)] (map list (take 4 teams) (reverse teams)))
((1 8) (2 7) (3 6) (4 5))
(let [[x & xs] [nil nil nil nil]] (every? #{x} xs))
false(let [args [nil 1 "foo" "sometimes" nil nil 100]] (keep identity args))
(1 "foo" "sometimes" 100)
(let [[first_12 & rest_85] (list 1 2 3)] (conj (vec rest_85) first_12))
[2 3 1]
(let [x (transient {})] (dotimes [n 100] (assoc! x n n)) (persistent! x))
{0 0, 1 1, 2 2, 3 3, 4 4, 5 5, 6 6, 7 7}
(let [f (fn [& x] (first x))] (apply f (iterate inc 0)))
0(let [x (atom [1 2 3])] (swap! x (partial apply +)) @x)
6(defn make-counter [] (let [counter (atom 0)] (fn [] (swap! counter inc) (deref counter))))
#'user/make-counter
(let [enables (into-array ["1" "2" "3"])] (doseq [x enables] (prn (Integer/parseInt x))))
nil"1\n2\n3\n"(let [weird #(into #{} [[Double/NaN Double/NaN] [Double/NaN Double/NaN]])] (= weird weird))
true(let [[foo bar] '(foo bar)] {(keyword foo) foo, (keyword bar) bar})
{:bar bar, :foo foo}
(let [x [1 2 3] y [4 5 6]] `(~@x ~y))
(1 2 3 [4 5 6])
(let [m {:foo 12, :bar 14, :baz 14}] (group-by m (keys m)))
{12 [:foo], 14 [:bar :baz]}
(let [[a b c & d] (range 10)] [a b c d])
[0 1 2 (3 4 5 6 7 8 9)]
(let [keys (cycle [:a :a# :b :c])] (zipmap keys (range 3 13)))
{:a 11, :a# 12, :b 9, :c 10}
(let [{:keys [l]} '(:l "list") {v 1} [:v "vector"]] [l v])
["list" "vector"]
(let [f (fn [x] (- x 5))] (vector (f 5) (f 6)))
[0 1]
(let [f (fn [] (fn [y] (inc y)))] (identical? (class (f)) (class (f))))
true(let [[a b c] '(1 2 3)] (vector a b c))
[1 2 3]
(defn palindromic? [s] (let [s (str s)] (= (seq s) (reverse s))))
#'user/palindromic?
(let [needs-two (fn [a b] (+ a b))] (->> 1 (needs-two 1)))
2(let [a "s"] (case (str (class a)) "java.lang.String" :found (str (class a))))
"class java.lang.String"(let [funcall (fn [f & args] (apply f args))] (funcall inc 1))
2(let [my-atom (atom {"aa" "a", "bb" "b"})] (swap! my-atom assoc-in ["bb"] "test"))
{"aa" "a", "bb" "test"}
(let [any (fn [s] (rand-nth (seq s)))] (any #{1 2 3}))
1(let [foo (range 20)] (concat (take 10 foo) ['insertedelement] (nthnext foo 10)))
(0 1 2 3 4 5 6 7 8 9 insertedelement 10 11 12 13 14 15 16 17 18 19)
(macroexpand '(let [a :a b :a] (hash-map a 1 b 2)))
(let [a :a b :a] (hash-map a 1 b 2))
(let [l [1 2 3] f (first l)] (concat (next l) [f]))
(2 3 1)
(let [[_ x & xs] [1 2 3 4 5]] [x xs])
[2 (3 4 5)]
(let [keys [:a :b :c]] (zipmap keys (map (fn [_] "whatever") keys)))
{:a "whatever", :b "whatever", :c "whatever"}
(let [x [1 2 3 4 0]] (map > x (rest x)))
(false false false true)
(let [{:keys [a b c]} {:a 1, :b 2}] (+ a 2))
3(let [{first-thing 0, last-thing 3} '[a b c d]] [first-thing last-thing])
[a d]
(let [keys (cycle [:a :a# :b :c])] (zipmap keys (range 21 109)))
{:a 105, :a# 106, :b 107, :c 108}
(let [xs [1 2 3 4 5]] (map list xs (rest xs)))
((1 2) (2 3) (3 4) (4 5))
(let [args '[some args]] `(defn any [~@(cons 'map args)]))
(clojure.core/defn user/any [map some args])
(let [{x 1, y 2} (seq [1 2 3 4])] [x y])
[2 nil]
(let [x [1 2 3] y [4 5 6]] `[~@x ~@y])
[1 2 3 4 5 6]
(let [syms (for [a (range 4)] (list 'foo a))] `(do ~@syms))
(do (foo 0) (foo 1) (foo 2) (foo 3))

