(let [vv [[1 2] [3 4] [5 6]]] [:table [:th "head"] (for [r vv] [:tr (for [i r] [:td i])])])
[:table [:th "head"] ([:tr ([:td 1] [:td 2])] [:tr ([:td 3] [:td 4])] [:tr ([:td 5] [:td 6])])]
(let [res (atom [])] (clojure.walk/prewalk #(do (when (number? %) (swap! res conj %)) %) {1 [2 #{3 4}]}) @res)
[1 2 4 3]
(let [m1 {:a 1, :b 2} m2 {:a 1, :b 2, :c 3}] (= m1 (select-keys m2 (keys m1))))
true(defn call-once [f] (let [value (atom nil)] (fn [& args] @(swap! value #(or % (delay (apply f args)))))))
#'user/call-once
(defn my-set [& args] (let [order (zipmap args (range))] (apply sorted-set-by (fn [a b] (- (order a) (order b))) args)))
#'user/my-set
(defmacro dolist [[v list] & body] `(loop [~v ~list] (when ~v (let [~v (first ~v)] ~@body) (recur (next ~v)))))
#'user/dolist
(let [m {:a 1, :b 2, :c 3, :d 4}] (apply = (repeatedly 100 #(zipmap (keys m) (vals m)))))
true(filter (let [found (atom false)] #(or @found (not (reset! found (= % 3))))) [1 2 3 4 3 5])
(1 2 4 3 5)
(let [t (atom {})] (doseq [i (range 20) j (range 20) k (range 20)] (swap! t assoc [j k] i)) @t)
{[8 8] 19, [7 6] 19, [8 7] 19, [16 6] 19, [3 15] 19, [8 11] 19, [16 19] 19, [9 8] 19, [7 1] 19, [10 14] 19, [5 19] 19, [12 12] 19, [8 9] 19, [7 12] 19, [2 18] 19, [8 18] 19, [12 18] 19, [12 6] 19, [15 4] 19, [13 3] 19, [10 5] 19, [13 15] 19, [15 11] 19, [11 9] 19, [11 2] 19, [4 3] 19, [7 11] 19, [17 5] 19, [19 6] 19, [2 2] 19, [12 17] 19, [7 13] 19, [18 12] 19, [19 16] 19, [0 0] 19, [9 18] 19, [3 ...
(defmacro defn' [name arglist & body] `(defn ~name ~arglist (let [&args ~(into {} (map (juxt keyword identity) arglist))] ~@body)))
#'user/defn'
(let [coll (vector 1 2 3 4) seq-version (seq coll)] {:coll (cons 5 coll), :seq (cons 5 seq-version)})
{:coll (5 1 2 3 4), :seq (5 1 2 3 4)}
(let [+ (fn [a b] (if (odd? a) (+ a b) (- a b)))] (+ 1 2) (+ 2 2))
0(let [m [[1 2 3] [4 7 2] [2 5 2]]] (for [row m] (for [cell row] (* 2 cell))))
((2 4 6) (8 14 4) (4 10 4))
(let [m {:a 1, :b 2, :c 3, :d 4}] ((juxt :a (apply juxt (disj (set (keys m)) :a))) m))
[1 [3 2 4]]
(let [a [1 2] b [3 4 5 6]] (concat (interleave a) (drop (count a) b) (drop (count b) a)))
(1 2 5 6)
(let [sz (count [1 2 3 4 5 6])] (rest (split-at (- sz 2) [1 2 3 4 5 6])))
((5 6))
(let [m {:a 1, :b 2, :c 3}] (zipmap (map #(str % "-san") (keys m)) (map inc (vals m))))
{":a-san" 2, ":b-san" 3, ":c-san" 4}
(let [remap (fn [f m] (into {} (map (fn [[k v]] {k (f v)}) m)))] (remap inc {:a 1, :b 3}))
{:a 2, :b 4}
(let [l1 ["a" "b" "c"] l2 [true false true]] (filter identity (map (fn [a b] (and b a)) l1 l2)))
("a" "c")
(let [f (fn [& {:keys [a b c], :or {a 1, b 2, c 3}, :as params}] (println params))] (f))
nil"nil\n"(defn round-rat [r] (let [f (rem r 1)] (if (< f 1/2) (- r f) (+ r (- 1 f)))))
#'user/round-rat
(let [v [:a :b :c :d :e :f :g] idx 2] (vec (concat (take idx v) (drop (inc idx) v))))
[:a :b :d :e :f :g]
(let [to-query (fn [m] (clojure.string/join "&" (for [[k v] m] (str (name k) "=" v))))] (to-query {:id 1, :mode true}))
"id=1&mode=true"(let [[a b] (split-with #(not= \: (first %)) '("a" "b" "c" ":d" "e"))] (concat a [(apply str b)]))
("a" "b" "c" ":de")
(let [c [1 2 3 4]] (every? #(= 1 %) (map #(- %2 %) c (drop 1 c))))
true(let [{:keys [amount name x], :strs [foo], :or {x 33}} {:amount 14, "foo" 88, :name "Carlos"}] [amount name x foo])
[14 "Carlos" 33 88]
(let [[x y z] (map inc [1 2 3])] [(-> x inc inc) (-> y inc inc) (-> z inc inc)])
[4 5 6]
(let [v [1 2 3 1 2 3] [before [x & after]] (split-with (complement #{3}) v)] (vec (concat before after)))
[1 2 1 2 3]
(let [s "12 3 456"] (when-let [[_ a b c] (seq (re-find #"(\d+) (\d+) (\d+)" s))] [a b c]))
["12" "3" "456"]
(let [f (fn [& args] (map #(str "like this? " %) args))] (f 1 2 3 :four "five" 6 :etc))
("like this? 1" "like this? 2" "like this? 3" "like this? :four" "like this? five" "like this? 6" "like this? :etc")
(let [v [:a :b :c :d :e]] (reduce into (subvec v 0 2) [[1 2 3 4] (subvec v 3 5)]))
[:a :b 1 2 3 4 :d :e]
(let [m1 {:a 1, :b 2} m2 {:b 3, :c 4}] (clojure.set/project [m1 m2] (clojure.set/intersection (set (keys m1)) (set (keys m2)))))
#{{:b 2} {:b 3}}
(reduce (fn [[mx sum] v] (let [update (+ v sum)] [(max update mx) update])) [0 0] [1 2 -30 8 12])
[3 -7]
(letfn [(lazy-bomb [n] (lazy-seq (if (zero? n) (println "BOOM!") (cons n (lazy-bomb (dec n))))))] (let [[x y] (lazy-bomb 1)] [x y]))
[1 nil]
"BOOM!\n"(defn swap-key [coll a b] (let [av (coll a) bv (coll b)] (-> coll (assoc a bv) (assoc b av))))
#'user/swap-key
(let [items [1 2 3 4 5 6 7]] (for [x items y items] (str x ", " y " ")))
("1, 1 " "1, 2 " "1, 3 " "1, 4 " "1, 5 " "1, 6 " "1, 7 " "2, 1 " "2, 2 " "2, 3 " "2, 4 " "2, 5 " "2, 6 " "2, 7 " "3, 1 " "3, 2 " "3, 3 " "3, 4 " "3, 5 " "3, 6 " "3, 7 " "4, 1 " "4, 2 " "4, 3 " "4, 4 " "4, 5 " "4, 6 " "4, 7 " "5, 1 " "5, 2 " "5, 3 " "5, 4 " "5, 5 " "5, 6 " "5, 7 " "6, 1 " "6, 2 " "6, 3 " "6, 4 " "6, 5 " "6, 6 " "6, 7 " "7, 1 " "7, 2 " "7,...
(let [date-str "2015-08-21" part-of-day-str "0-0-0.4" parse-date (fn [s] (map #(Double/parseDouble %) (clojure.string/split s #"-")))] (map + (parse-date date-str) (parse-date part-of-day-str)))
(2015.0 8.0 21.4)
(let [keywordify (fn [m] (if (map? m) (into {} (map (fn [[k v]] [(keyword k) v]) m)) m))] (keywordify {"foo" {"bar" 12}}))
{:foo {"bar" 12}}
(defmacro sym-meta "Despite Bronsa" [sym] (let [immediate (meta sym) env (-> &env (find sym) (some-> key) meta)] (merge env immediate)))
#'user/sym-meta
(let [input {:a 0, :b 1}] (reduce (fn [m [k v]] (assoc m k v [k k] [v v])) input input))
{:a 0, :b 1, [:a :a] [0 0], [:b :b] [1 1]}
(letfn [(lazy-bomb [n] (lazy-seq (if (zero? n) (println "BOOM!") (cons n (lazy-bomb (dec n))))))] (let [[x y] (lazy-bomb 2)] [x y]))
[2 1]
(do (let [col (for [x (range 50) y (range 1 50)] [x y])] (reduce #(map + %1 %2) col)) nil)
nil(let [m [{:foo "beta"} {:foo "grammar"} {:foo "zalpha"}]] (apply max-key #(read-string (clojure.string/replace (format "36r%-10s" (:foo %)) " " "0")) m))
{:foo "zalpha"}
(let [v [{:name "Chris", :age 28} {:name "Adam", :age 25}] m (zipmap (map :name v) v)] (update-in m ["Chris" :age] inc))
{"Adam" {:age 25, :name "Adam"}, "Chris" {:age 29, :name "Chris"}}
(let [coll [:N :NE :E :SE :S :SW :W :NW]] (map #(nth coll (rem % (count coll))) (range 6 11)))
(:W :NW :N :NE :E)
(let [a [1 2 1 2 3] b [4 3 4 2 4 1 0]] [(map a b) (map b a)])
[(3 2 3 1 3 2 1) (3 4 3 4 2)]
(defn safe-comp [& fs] (fn [& args] (reduce #(let [r (%2 %1)] (if (nil? r) (reduced nil) r)) args fs)))
#'user/safe-comp
(defn str-swap [s index-a index-b] (let [v (vec s)] (apply str (assoc v index-a (get v index-b) index-b (get v index-a)))))
#'user/str-swap
(defmacro casca-fn [name doc v1 v2] `(defn ~name ~doc [arg#] (let [source# (hfs-whole-file arg#)] (<- ~(vec v1) (source# ~@v2)))))
#'user/casca-fn
(let [hello (fn [x y] (str "hi " x " and " (y))) robert (fn [] (str "blah"))] (map hello [1] [robert]))
("hi 1 and blah")

