(let [n [:a :b :c] r [22 33]] (replace r (take 5 (interleave n (range 3)))))
(:a 22 :b 33 :c)
(let [fib (promise)] (deliver fib (lazy-cat [1 1] (map + @fib (rest @fib)))) (take 10 @fib))
(1 1 2 3 5 8 13 21 34 55)
(let [x (for [x (take 10 (iterate inc 0))] (do (println "Evaling" x) [x]))] (first x))
[0]
"Evaling 0\n"(let [[first-row second-row third-row] (partition 3 [1 2 3 4 5 6 7 8 9])] third-row)
(7 8 9)
(defmacro with-tokens [& body] `(let [tokens# (yaml/parse-string (slurp "tokens.yml")) {:keys [consumer_key access_key]} tokens#] (do ~@body)))
#'user/with-tokens
(let [{:keys [a b], :as m} {:a 1, :b 2}] (-> m (assoc :c (inc a))))
{:a 1, :b 2, :c 2}
(let [m {:foo 12, :bar 14, :baz 14}] (filter #(= 14 (m %)) (keys m)))
(:bar :baz)
(let [foo {:bar 'test} bar :bar] ['[foo bar] '(foo bar) [foo bar] (foo bar)])
[[foo bar] (foo bar) [{:bar test} :bar] test]
(let [qsort (fn qs [[p :as l]] (if p (let [{f 1, p 0, l -1} (-> (partial compare p) (group-by l))] (lazy-cat (qs f) p (qs l)))))] (qsort [5 1 8 3 2 0]))
(0 1 2 3 5 8)
(let [sorted-coll (-> (range 25) sort) target 18] (loop [vs (range (count sorted-coll)) res {}] (let [v (first vs)] (if (get res (- v target)) res (recur (next vs) (assoc res v (- target v)))))))
{0 18, 1 17, 2 16, 3 15, 4 14, 5 13, 6 12, 7 11, 8 10, 9 9, 10 8, 11 7, 12 6, 13 5, 14 4, 15 3, 16 2, 17 1}
(first (remove #(> % 0.5) (repeatedly (fn [] (let [r (rand)] (print r " ") r)))))
0.3831263813729716"0.3831263813729716 "(let [lists (list '("foo" "bar") '("baz" "booo!"))] (for [list lists item list] (.length item)))
(3 3 3 5)
(let [to-call (atom +)] [(map @to-call (range 3)) (do (reset! to-call -) (map @to-call (range 3)))])
[(0 1 2) (0 -1 -2)]
(let [ops {"+" +, "-" -, "*" *, "/" /} this-op (ops "*")] (this-op 2 4))
8(let [s [1 2 3]] (apply array-map (interleave s (for [n s] (str "Number: " n)))))
{1 "Number: 1", 2 "Number: 2", 3 "Number: 3"}
(let [[a b] (split-with (partial not= 2) [1 2 2 2 1])] (concat a (rest b)))
(1 2 2 1)
(let [v [1 2 3 4] n 1] (concat (subvec v n) (subvec v 0 n)))
(2 3 4 1)
(let [{:keys [a b], :as m} {:a 1, :b 2}] (-> m (assoc :b (inc a))))
{:a 1, :b 2}
(let [[prefix > a b c] [1 2 3 4 5 6]] [prefix a b c])
[1 3 4 5]
(let [p (memoize println)] (doseq [i [1 2 3 2 1 0 1 2]] (p i)))
nil"1\n2\n3\n0\n"(defn or-comp [args & fns] (let [results (for [fn fns] (fn args))] (some (complement nil?) results)))
#'user/or-comp
(let [m {:a nil, :b :foo}] (reduce #(dissoc % %2) m (filter nil? (keys m))))
{:a nil, :b :foo}
(let [x (range 10)] (interleave (map inc (take-nth 2 x)) (map dec (take-nth 2 (rest x)))))
(1 0 3 2 5 4 7 6 9 8)
(let [s "[^[][['+\ufeff\\"] (->> s (map (comp (partial format "\\u%04x") int)) (apply str) (re-pattern)))
#"\u005b\u005e\u005b\u005d\u005b\u005b\u0027\u002b\ufeff\u005c"
(let [a (atom 3) b (atom 4) s #{a b}] (swap! a inc) (count s))
2(let [x '(a b c d e f g)] [(take 2 x) (drop 2 x)])
[(a b) (c d e f g)]
(defmacro call* [obj getter & args] `(let [var# ~obj] (((keyword '~getter) (class* var#)) var# ~@args)))
#'user/call*
(let [splitter 2 coll [:a :b :c :d]] (mapv vec [(take splitter coll) (drop splitter coll)]))
[[:a :b] [:c :d]]
(let [[f & a] '(* 5 3)] [(apply * '(5 3)) (apply f a)])
[15 3]
(defn foo [x & xs] (let [xs (if (coll? (first xs)) (first xs) xs)] [x xs]))
#'user/foo
(let [coll [nil false 0 ""]] (reduce #(when (= %2 :hooray) (reduced %2)) nil coll))
nil(let [latin1 (apply str (map char (range 32 255)))] (apply str (re-seq #"\p{L}" latin1)))
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzªµºÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ"(let [not-number #_(+ 1 2 (* 3 5)) "is a string" #_(dumb-binding-unwanted nil)] not-number)
"is a string"(let [v [\a \b \c \d] poses [1 4]] (apply assoc v (interleave poses (repeat \space))))
[\a \space \c \d \space]
(let [latin1 (apply str (map char (range 32 255)))] (apply str (re-seq #"\p{Ll}" latin1)))
"abcdefghijklmnopqrstuvwxyzµßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ"(let [d {1 2, 2 3, 3 2}] (map count [(set (keys d)) (set (vals d))]))
(3 2)
(let [{:syms [foo], :keys [foo], :strs [foo]} {'foo 1, "foo" 2, :foo 3}] [foo foo foo])
[2 2 2]
(let [a (atom [10 20 30 40])] (println @a) (swap! a assoc 2 99) (println @a))
nil"[10 20 30 40]\n[10 20 99 40]\n"(let [s #{:a} ss (sorted-set-by (constantly 1) :a)] [(some ss s) (some s ss)])
[nil :a]
(let [[a b c] [[1 2 3] [4 5 6] [7 8 9]]] (reduce + a))
6(let [[p & col :as all] [1 2 3]] (print "p:" p "col:" col "all:" all))
nil"p: 1 col: (2 3) all: [1 2 3]"(let [[a b] (split-with (partial not= 3) [1 2 3 4 5])] (concat a (rest b)))
(1 2 4 5)
(let [m {"a" {:value "b"}}] (reduce (fn [[k v]] (str k (apply str (vals v)))) m))
["a" {:value "b"}]
(let [m {:one 1, :two [{:three 3, :four 4}]}] (apply into m (filter seq? (vals m))))
{:one 1, :two [{:four 4, :three 3}]}
(let [m {:a 1, :b 2, :c 3, :d 4}] (reduce (partial dissoc m) [:b :c]))
{:a 1, :d 4}
(let [append-to-self (comp (partial apply conj) (juxt (fnil identity []) identity))] (map append-to-self [[] [1] [2 3] nil]))
([[]] [1 [1]] [2 3 [2 3]] [nil])
(let [[_ s1 s2] (re-matches #"(-?\d+)/(\d+)" "17/18")] (/ (Integer. s1) (Integer. s2)))
17/18(let [mystery (identity Double/NaN) mystery (. Double NaN)] [(= mystery mystery) (= mystery mystery)])
[true false]
(let [as [1 2 3] bs [:c :d :e]] (for [a as b bs] [a b]))
([1 :c] [1 :d] [1 :e] [2 :c] [2 :d] [2 :e] [3 :c] [3 :d] [3 :e])
(#(let [x (sort (list % %2))] (if (.equals (first x) %) 1 -1)) "booc" "aood")
-1

