(let [m [[0 0] [0 0]]] (assoc m 0 (assoc (nth m 0) 0 1)))
[[1 0] [0 0]]
(let [_ (apply println [1 2 3 4 5]) _ (println "should happen second")] nil)
nil"1 2 3 4 5\nshould happen second\n"(let [l '(1 2 3 4 5)] (concat (take 2 l) (nthrest l 3)))
(1 2 4 5)
(let [s (new java.io.StringWriter)] (binding [*out* s] (println "hello world") (println "nice weather") (str s)))
"hello world\nnice weather\n"(let [a (into-array (range 5)) v (vec a)] (aset a 0 17) (get v 0))
17(defn myfun [pred foo a b] (let [filtered-a (filter pred a)] (map foo a b)))
#'user/myfun
(let [x (with-meta (lazy-seq (seq "foo")) {:bar 2})] [(class x) (meta x) (apply str x)])
[clojure.lang.LazySeq {:bar 2} "foo"]
(let [e-m-m-m (fn [list] (nth list (mod 15 (count list))))] (e-m-m-m '(pizza pork pb-and-j)))
pizza(let [a ['a 'b] b [1 2 3]] (cons (first b) (interleave a (rest b))))
(1 a 2 b 3)
(defmacro foo [& body] `(let [a# 9] (macrolet [(~'bar [] `(+ 1 ~a#))] ~@body)))
#'user/foo
(let [x (iterate inc 0)] (take 10 (concat (take 3 x) [-1] (drop 3 x))))
(0 1 2 -1 3 4 5 6 7 8)
(let [[first & [second] & rest :as s] [1 2 3]] [first second rest s])
[1 2 (2 3) [1 2 3]]
(let [[a b :as all] [1 2 3 4]] {:a a, :b b, :all all})
{:a 1, :all [1 2 3 4], :b 2}
(let [a (into-array [1 2 3]) p (seq a) _ (aset a 0 1)] p)
(1 2 3)
(let [a (atom nil)] (reset! a (lazy-seq (cons 1 (map inc @a)))) (take 4 @a))
(1 2 3 4)
(let [l [1 2 3 4 5 6]] [(take-nth 2 l) (take-nth 2 (rest l))])
[(1 3 5) (2 4 6)]
(let [maxrange 1000] (reduce + (distinct (concat (range 3 maxrange 3) (range 5 maxrange 5)))))
233168(let [f (fn [& args] (println args))] (f 1 2 3) (f 4 5 6))
nil"(1 2 3)\n(4 5 6)\n"(let [{:keys [a b c]} {:a 0, :b 1, :c 2}] (+ a b c))
3(meta (let [discard #(with-meta % nil)] (binding [*data-readers* {'foo discard}] (read-string "#foo ^:baz []"))))
nil(let [a (list 1 2 3) b (cons 4 a)] (identical? a (rest b)))
true(let [a 1 b 2 c 3] [(list a b c) '(a b c)])
[(1 2 3) (a b c)]
(let [m {:a 1, :b 3, :c 2}] (apply hash-map (interleave (vals m) (keys m))))
{1 :a, 2 :c, 3 :b}
(let [s [1 1 3 4 5 6]] [(take-nth 2 s) (take-nth 2 (rest s))])
[(1 3 5) (1 4 6)]
(let [m {:first 31, :second 63, :third 127}] (zipmap (keys m) (map inc (vals m))))
{:first 32, :second 64, :third 128}
(let [[first & [second :as rest] :as s] [1 2 3]] [first second rest s])
[1 2 (2 3) [1 2 3]]
(do (defrecord R [a b]) (let [r (->R :x :y)] (= r (read-string (pr-str r)))))
true(let [{a :argh, :keys [b c]} {:argh 1, :b 2, :c 3}] [a b c])
[1 2 3]
(let [my-coll (range 6)] (reduce (fn [prev curr] (conj prev curr)) [(first my-coll)] (rest my-coll)))
[0 1 2 3 4 5]
(let [ops (juxt + - *)] (take 10 (map ops (range) (range 20 10 -2))))
([20 -20 0] [19 -17 18] [18 -14 32] [17 -11 42] [16 -8 48])
(let [[k v] (rand-nth (seq {:a 0, :b 1, :c 2}))] {:key k, :value v})
{:key :b, :value 1}
(let [m {:a {0 "a", 1 "b"}, :b {4 "z", 1 "c"}}] ((m :a) 1))
"b"(let [x [1 2 3 4 5]] (into (subvec x 0 1) (subvec x 2)))
[1 3 4 5]
(let [vs [[1 2 3] [4 5 6]]] (for [v vs el v] {:a el}))
({:a 1} {:a 2} {:a 3} {:a 4} {:a 5} {:a 6})
(let [listify #(if (vector? %) % (vector %))] (map listify [1 [1 2 3]]))
([1] [1 2 3])
(let [[[k k2] n n2] [[2 3] [0 6] [1 3]]] [k k2 n n2])
[2 3 [0 6] [1 3]]
(let [a {:a []} c [{:a 2} {:a 3}]] (map (partial merge-with conj a) c))
({:a [2]} {:a [3]})
(defmacro env [] (let [symbols (keys &env)] (zipmap (map (fn [sym] `(quote ~sym)) symbols) symbols)))
#'user/env
(let [coll? (some-fn coll? string?)] (remove coll? (tree-seq coll? seq {:a 1, :b [3 "hello"]})))
(:a 1 :b 3 \h \e \l \l \o)
(let [[_ fruit _] (get-in {:foo {:bar {:baz ["cat" "apple" "car"]}}} [:foo :bar :baz])] fruit)
"apple"(map class (let [f (fn [n] (reify clojure.lang.IDeref (deref [this] n)))] (map f (range 5))))
(sci.impl.opts$default_reify_fn$reify__33986 sci.impl.opts$default_reify_fn$reify__33986 sci.impl.opts$default_reify_fn$reify__33986 sci.impl.opts$default_reify_fn$reify__33986 sci.impl.opts$default_reify_fn$reify__33986)
(let [coll (range 4)] (do (pr coll) (print " ") (map inc coll) (pr coll)))
nil"(0 1 2 3) (0 1 2 3)"(let [a "foo" b "bar"] (str "Hello " a ", how are you? -" b))
"Hello foo, how are you? -bar"(defmacro dump [expr] `(let [val# ~expr] (println (pr-str '~expr) (type val#) "->" (pr-str val#))))
#'user/dump
(let [roll (fn [] (repeatedly 5 #(rand-int 100)))] (map #(vector % (roll)) (range 10)))
([0 (20 3 68 97 65)] [1 (29 20 57 32 64)] [2 (0 66 21 97 63)] [3 (88 29 13 10 68)] [4 (45 20 11 74 16)] [5 (40 96 76 13 93)] [6 (29 17 27 32 42)] [7 (67 1 40 70 59)] [8 (22 11 60 5 66)] [9 (4 25 33 10 64)])
(let [v [1 2 3]] (reduce #(update-in %1 [%2] inc) v (range (count v))))
[2 3 4]
(let [x 5 l (- (int (/ x 2))) r (+ l x)] [l r])
[-2 3]
(let [f (partial * 2)] (mapcat (juxt identity f) [1 2 3 4 5 6]))
(1 2 2 4 3 6 4 8 5 10 6 12)
(map #(let [[x y] %] (+ x y)) [[1 2] [2 3] [3 4]])
(3 5 7)
(let [f (fn [x] (+ 2 x)) newfn (comp f *)] (newfn 5 8))
42

