(let [f (fn [a b c & more] (+ a b c (first more)))] (apply f (range)))
6(let [m {} port 4] (if (not-any? #(= port %) '(nil -1)) (assoc m :port port)))
{:port 4}
(let [items '[a b c]] (for [x items y items :when (not= x y)] [x y]))
([a b] [a c] [b a] [b c] [c a] [c b])
(let [coll {#"foo" 1, #"bar" 2, #"foobar" 3}] (map coll (filter #(re-matches % "foo") (keys coll))))
(1)
(let [** (fn ** ([] 1) ([n] n) ([n ex] (apply * (repeat ex n))))] (** 2 3))
8(defmacro as->> [name & args] (let [forms (butlast args) expr (last args)] `(as-> ~expr ~name ~@forms)))
#'user/as->>
(let [s " S I I ( S I I)"] (read-string (str "[" s "]")))
[S I I (S I I)]
(defmacro with-ns [opts & body] `(let [ns# *ns*] (ns ~(gensym) ~@opts) ~@body (in-ns (ns-name ns#))))
#'user/with-ns
(let [x true y false z true] (if (= [x y z] [true false true]) "yes" "no"))
"yes"(let [{t true, f false} (frequencies (repeatedly 1000 #(rand-nth [true false])))] (/ t (+ t f)))
507/1000(let [{:keys [a b c]} {:a #{1 2 3}, :b 2, :c 3}] [a b c])
[#{1 2 3} 2 3]
(let [mw (fn mw [& r] (apply merge-with mw r))] (mw {:a {:b 2}} {:a {:c 3}}))
{:a {:b 2, :c 3}}
(clojure.walk/walk #(let [[k v] %] [k (* 10 v)]) identity {:a 1, :b 2, :c 3})
{:a 10, :b 20, :c 30}
(let [f #(< % 5) xs (range 15)] (list (filter f xs) (remove f xs)))
((0 1 2 3 4) (5 6 7 8 9 10 11 12 13 14))
(let [v [:a :b :c]] (vec (map v (filter #(not (= % 1)) (range (count v))))))
[:a :c]
(let [x (list 1 2 3)] [(= x [1 2 3]) (= `[~@x] [1 2 3])])
[true true]
(let [{{:keys [bar baz]} :params, :as request} {:params {:bar 0, :baz 1}}] [bar baz (+ bar baz)])
[0 1 1]
(let [m {:a "apple", :b "banana", :c "cherry"} keys [:a :b]] (clojure.string/join "." (map m keys)))
"apple.banana"(let [{x :x, y :y, z :z} '(:x 0 :y 1 :z 42)] [x y z])
[0 1 42]
(let [rands (partition 4 (repeatedly 20 #(rand-int 100)))] (into {} (map vector [:age :name :pos :cos] rands)))
{:age (30 34 50 58), :cos (45 62 92 58), :name (66 29 87 4), :pos (54 85 93 38)}
(let [a {:a []} c [{:a 2} {:a 3}]] (reduce (partial merge-with conj) {:a []} (conj c a)))
{:a [2 3 []]}
(let [hm (hash-map)] (map (fn [k v] (assoc hm k v)) ["a" "b" "a"] [1 2 3]))
({"a" 1} {"b" 2} {"a" 3})
(let [s ["a" "b" "c" "d"]] (for [[i e] (map vector (range (count s)) s)] [e i]))
(["a" 0] ["b" 1] ["c" 2] ["d" 3])
(let [All-languages {:Clojure 0, :C++ 3, :java 5}] (> (:Clojure All-languages) (apply + (vals (dissoc All-languages :Clojure)))))
false(defn and2 ([] true) ([test] (test)) ([test & more] (let [r (test)] (if r (apply and2 more) r))))
#'user/and2
(let [coll (range 1 10) n 3] (for [offset (range n)] (take-nth n (drop offset coll))))
((1 4 7) (2 5 8) (3 6 9))
(let [orig {:a 1, :b 2}] (merge orig (select-keys {:c 3, :d 4, :g 5} [:c :g])))
{:a 1, :b 2, :c 3, :g 5}
(let [int-gensym (fn [] (Integer/parseInt (.substring (name (gensym)) 3))) a (int-gensym) b (int-gensym)] [a b (- b a)])
[106348 106349 1]
(let [s "a,bcde,f,gh" h ","] (for [x (range (count s)) :when (.startsWith (subs s x) h)] x))
(1 6 8)
(let [old "12345" new "-B-D-"] (reduce str (map #(if (= \- %2) %1 %2) old new)))
"1B3D5"(let [l [1 2 3 4]] (for [i l j l :while (not= i j)] [j i]))
([1 2] [1 3] [2 3] [1 4] [2 4] [3 4])
(defn remove-first [coll item] (let [sp (split-with (partial not= item) coll)] (concat (butlast (first sp)) (second sp))))
#'user/remove-first
(defn remove-first [coll item] (let [sp (split-with (partial not= item) coll)] (concat (first sp) (rest (second sp)))))
#'user/remove-first
(defn arraylist-rseq [al] (let [n (count al) it (.listIterator al n)] (for [i (range n)] (.previous it))))
#'user/arraylist-rseq
(defn list-rseq [xs] (let [n (count xs)] (for [i (range n)] (nth xs (- n i 1)))))
#'user/list-rseq
(mapv #(reduce + %) (let [points [[1 1] [2 2] [3 5]]] (apply map vector points)))
[6 8]
(let [[a & b :as keys] (seq [1 2 3 4 5 6 78])] [a b keys])
[1 (2 3 4 5 6 78) (1 2 3 4 5 6 78)]
(let [lazy-eq (reify Object (equals [me them] (if (nil? them) false (.equals them me))))] (= lazy-eq lazy-eq))
true(defn seq-filter-expr [f s] (mapcat #(let [rtn (f %)] (if (= true rtn) % rtn)) s))
#'user/seq-filter-expr
(let [world (-> nil (assoc-in [:1 :2] "data") (assoc-in [:3 :5] 9))] (update-in world [:3 :5] dec))
{:1 {:2 "data"}, :3 {:5 8}}
(let [map (fn [f coll] (identity coll))] (map char (map (fn [_] (.toString nil)) [66 67 68])))
(\B \C \D)
(let [m [{:foo "beta"} {:foo "gamma"} {:foo "alpha"}]] (apply max-key #(read-string (str "36r" (:foo %))) m))
{:foo "gamma"}
(let [x (transient (apply hash-map (range 20)))] (dotimes [n 100] (assoc! x n n)) (sort (persistent! x)))
([0 0] [1 1] [2 2] [3 3] [4 4] [5 5] [6 6] [7 7] [8 8] [9 9] [10 10] [11 11] [12 12] [13 13] [14 14] [15 15] [16 16] [17 17] [18 18] [19 19] [20 20] [21 21] [22 22] [23 23] [24 24] [25 25] [26 26] [27 27] [28 28] [29 29] [30 30] [31 31] [32 32] [33 33] [34 34] [35 35] [36 36] [37 37] [38 38] [39 39] [40 40] [41 41] [42 42] [43 43] [44 44] [45 45] [46 46] [47 47] [48 48] [49 49] [50 50] [51 51] [52...
(defmacro m [sets] (#(let [syms (repeatedly (count sets) gensym)] `(for [~@(interleave syms sets)] [~@syms]))))
#'user/m
(let [a 23] (doseq [b (range 24)] (print (rem (min (- a b) (- b a)) 24))))
nil"-23-22-21-20-19-18-17-16-15-14-13-12-11-10-9-8-7-6-5-4-3-2-10"(let [op (first '(+ 1 2)) rst (rest '(+ 1 2))] (apply (resolve op) rst))
3(let [path ["5" "6" "7" "3"] ds {"5" {"6" {"7" {"3" {:words {"close" 1}}}}}}] (get-in ds path))
{:words {"close" 1}}
(let [vec-order (zipmap [:b :a :c] (range))] (into (sorted-map-by (comparator vec-order)) {:a 1, :b 5, :c 6}))
{:a 1, :b 5, :c 6}
(defn clamp [minimum maximum x] (let [clamp-bottom (max x (or minimum x))] (min clamp-bottom (or maximum clamp-bottom))))
#'user/clamp
(let [{:keys [a b], :as m} {:a 1, :b 2} c (inc a) d (inc c)] d)
3

