(let [[w1 w2 w3 :as words] (clojure.string/split "hello how are you doing?" #"\s+")] (take 3 words))
("hello" "how" "are")
(defmacro with-req-body [req & body] `(with-open [r# (~req :body)] (let [buf# (BufferedReader. (InputStreamReader. r#))] body)))
#'user/with-req-body
(defn two-of-each [xs] (let [x (first xs)] (if (not-empty xs) [] (concat [x x] (recur (rest xs))))))
#'user/two-of-each
(let [lines (map #(clojure.string/split % #"_") ["1_2" "b_c" "3_4"])] (map (partial zipmap [:a :b]) lines))
({:a "1", :b "2"} {:a "b", :b "c"} {:a "3", :b "4"})
(let [m (memoize conj)] [(m [1 2 3] 4) (m (list 1 2 3) 4)])
[[1 2 3 4] [1 2 3 4]]
(defn switcheroo! [atom newval] (let [oldval @atom] (if (compare-and-set! atom oldval newval) oldval (recur atom newval))))
#'user/switcheroo!
(let [{:keys [a b c], :or [1 2 3]} {:a 5, :b 6}] [a b c])
[5 6 nil]
(let [a (promise) b (list* 1 2 3 (lazy-seq @a))] (deliver a b) (take 20 b))
(1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2)
(let [br (java.io.StringReader. "foo")] (->> (repeatedly #(.read br)) (take-while #(not= % -1)) (map char)))
(\f \o \o)
(let [m {:one 1, :two [{:three 3, :four 4}]}] (apply into m (filter coll? (vals m))))
{:four 4, :one 1, :three 3, :two [{:four 4, :three 3}]}
(let [f (fn f [x] (if (> x 10) x (f (* x 3))))] (f 1))
27(let [[_ a b _ c] '(1 2 3 4 5)] (println a b c))
nil"2 3 5\n"(let [coll [nil false 0 "" :hooray]] (reduce #(when (= %2 :hooray) (reduced %2)) [] coll))
:hooray(let [triangle (for [i (range 5)] (range i))] (for [row (range (count triangle))] (get triangle row)))
(nil nil nil nil nil)
(let [v [1 2 3 4 5 6] size (count v)] (subvec v (- size 2)))
[5 6]
(let [a (object-array 32) v (vec a)] (aset a 0 v) (= v (v 0)))
true(let [accumulator (atom {})] (swap! accumulator #(update-in % [:p1 :p2 :p3] (fnil + 0) 1)) @accumulator)
{:p1 {:p2 {:p3 1}}}
(let [f #(inc %) m (memoize #(println (% 1)))] (m f) (m f))
nil"2\n"(let [{a 3, b 0, c 5} [1 2 3 4 5 6]] [a b c])
[4 1 6]
(defmacro cons-when [x xs] `(let [first# ~x rest# ~xs] (if first# (cons first# rest#) rest#)))
#'user/cons-when
(defmacro as-> [expr name & forms] `(let [~name ~expr ~@(interleave (repeat name) forms)] ~name))
#'user/as->
(let [x [{:a 1} {:b 2}] y [{:x 1} {:y 2}]] (map merge x y))
({:a 1, :x 1} {:b 2, :y 2})
(defmacro bar [a] `(defn foo (let [tail []] (if (even? a) (cons a tail) tail))))
#'user/bar
(let [{:keys [x y]} {:x 1, :y 2}] (println "x: " x ", y: " y))
nil"x: 1 , y: 2\n"(let [x '(+ 2 3) op (first x) args (rest x)] (apply (resolve op) args))
5(let [kvs (repeatedly 20 #(rand-int 100))] (println "kvs =" kvs "\nsorted-map =" (apply sorted-map kvs)))
nil"kvs = (56 65 81 93 68 27 46 47 52 34 51 43 13 46 89 52 74 12 97 43) \nsorted-map = {13 46, 46 47, 51 43, 52 34, 56 65, 68 27, 74 12, 81 93, 89 52, 97 43}\n"(let [nums [1 2 3]] (map (fn [[f s]] (/ s f)) (partition 2 1 nums)))
(2 3/2)
(let [foo ((partial (juxt filter remove) odd?) [1 2 3 4 5])] (take 1 (first foo)))
(1)
(let [prn #(do (prn %) %)] ((prn +) (prn 4) (prn ((prn -) (prn 1)))))
3"#object[clojure.core$_PLUS_ 0x35b52c2b \"clojure.core$_PLUS_@35b52c2b\"]\n4\n#object[clojure.core$_ 0x173365be \"clojure.core$_@173365be\"]\n1\n-1\n"(defn return-truthy [it ob] (let [[f & r] (iterate it ob)] (take-while (partial not= f) r)))
#'user/return-truthy
(let [{:keys [a b c], :or {:a 0, :b 1}, :as point} {}] [[a b c] point])
[[nil nil nil] {}]
(let [n1 -5 n2 -5N] [(= n1 n2) (= #{n1} #{n2}) (= [n1] [n2])])
[true true true]
(let [sds [[:a :b :c] [:d :e :f :g]]] (doseq [item sds] (println (nth item 2))))
nil":c\n:f\n"(let [options {:a first, :b second} type :a data [0 1 2 3]] ((options type) data))
0(let [m ["the" "quick" "brown" "fox"]] ((juxt (partial apply max-key count) (partial apply min-key count)) m))
["brown" "fox"]
(let [a (atom 0)] (second (map (fn [_] (swap! a inc)) (filter identity (range 50)))) @a)
32(let [values {2 :urgent, 3 :very}] (map #(update-in % [:classification] values) [{:classification 2} {:classification 3}]))
({:classification :urgent} {:classification :very})
(let [s #{1 2 3 4 7 9}] (clojure.set/difference (set (range (apply max s))) s))
#{0 5 6 8}
(let [{:keys [name age]} {:name "Joe", :age 30}] (format "Saw %s, %d years old" name age))
"Saw Joe, 30 years old"(let [x {:holder (atom nil)} x-holder [x]] (swap! (:holder x) (constantly x-holder)) (identical? x-holder (:holder x)))
false(let [[a b c & more] [:a :b :c :d :e :f]] [a b c more])
[:a :b :c (:d :e :f)]
(defn remove-first [coll] (let [sp (split-with (partial = :b) coll)] (concat (butlast (first sp)) (second sp))))
#'user/remove-first
(defn iter [fn init] (lazy-seq (cons init (let [v (fn init)] (cons v (iter fn v))))))
#'user/iter
(let [a (atom (range 5))] (str (first (swap! a rest)) " " (first (swap! a rest))))
"1 2"((fn [& a] (let [{:keys [x y]} (apply hash-map a)] [x y])) :x 1 :y 2)
[1 2]
(let [all ["a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z" "0" "1" "2" "3" "4" "5" "6" "7" "8" "9"]] (nth (iterate #(for [base % more all] (str base more)) all) 1))
("aa" "ab" "ac" "ad" "ae" "af" "ag" "ah" "ai" "aj" "ak" "al" "am" "an" "ao" "ap" "aq" "ar" "as" "at" "au" "av" "aw" "ax" "ay" "az" "a0" "a1" "a2" "a3" "a4" "a5" "a6" "a7" "a8" "a9" "ba" "bb" "bc" "bd" "be" "bf" "bg" "bh" "bi" "bj" "bk" "bl" "bm" "bn" "bo" "bp" "bq" "br" "bs" "bt" "bu" "bv" "bw" "bx" "by" "bz" "b0" "b1" "b2" "b3" "b4" "b5" "b6" "b7" "b8" "b9" "ca" "cb" "cc" "cd" "ce" "cf" "cg" "ch"...
(let [hello (fn [{:keys [name], :or {:name "unknown person"}}] (println "hello, " name))] (hello {:name "constantine"}))
nil"hello, constantine\n"(let [{:keys [a b c], :or {a 0, b 1}, :as point} {}] [[a b c] point])
[[0 1 nil] {}]
(let [s #{1 2 3} k 1] (conj (disj s k) (inc (get s k))))
#{2 3}
(let [ids ["a1" "b2" "c3"]] (clojure.string/join "&" (map #(str "ids=[" % "]") ids)))
"ids=[a1]&ids=[b2]&ids=[c3]"

