(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 [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 [[a b c d] (map inc [1 2 3 4])] (println a b c d))
nil"2 3 4 5\n"(let [[w1 w2 w3 :as words] (clojure.string/split "hello how are you doing?" #"\s+")] (take 3 words))
("hello" "how" "are")
(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]
(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})
(let [adder (fn [x] #(+ x %))] (do (println (type (adder 3))) (type (adder 3))))
sci.impl.fns$fun$arity_1__26688"sci.impl.fns$fun$arity_1__26688\n"(let [x [] y (conj x '(filter #(= 3 %) (range 1000)))] (comment "blah blah"))
nil(let [coll [nil false 0 "" :hooray]] (reduce #(when (= %2 :hooray) (reduced %2)) [] coll))
:hooray(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 [{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
(let [triangle (for [i (range 5)] (range i))] (for [row (range (count triangle))] (get triangle row)))
(nil nil nil nil nil)
(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 [f #(inc %) m (memoize #(println (% 1)))] (m f) (m f))
nil"2\n"(defmacro bar [a] `(defn foo (let [tail []] (if (even? a) (cons a tail) tail))))
#'user/bar
(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 [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"(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 [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 [[a b c & more] [:a :b :c :d :e :f]] [a b c more])
[:a :b :c (:d :e :f)]
(defn fix [f x] (let [y (f x)] (if (= x y) x (recur f y))))
#'user/fix
(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 [a (atom 0)] (second (map (fn [_] (swap! a inc)) (filter identity (range 50)))) @a)
32(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 [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]"(defn remove-first [coll] (let [sp (split-with (partial = :b) coll)] (concat (butlast (first sp)) (second sp))))
#'user/remove-first
(let [hello (fn [{:keys [name], :or {:name "unknown person"}}] (println "hello, " name))] (hello {:name "constantine"}))
nil"hello, constantine\n"(let [v [1 2 3 4] n 3] (concat (subvec v n) (subvec v 0 n)))
(4 1 2 3)
(let [{x :x, y :y, {z :z} :y} {:x 10, :y {:z 20}}] [x y z])
[10 {:z 20} 20]
(let [li (lazy-cat [1 2 3 (lazy-seq (prn "hi"))])] (first (filter #(= 3 %) li)))
3"\"hi\"\n"

