(let [m [[1 2 3] [4 7 2] [2 5 2]]] (for [row m] (map #(* 2 %) row)))
((2 4 6) (8 14 4) (4 10 4))
(let [m {:a 1, :b 2, :c 3}] (into (empty m) (map (juxt key (comp (partial * 10) val)) m)))
{:a 10, :b 20, :c 30}
(let [weird #(into #{} [[Double/NaN Double/NaN] [Double/NaN Double/NaN]]) weird2 #(into #{} [[Double/NaN Double/NaN] [Double/NaN Double/NaN]])] (= weird weird2))
false(let [a (delay (do (println "forced a") (+ 1 1))) b (delay (do (println "forced b") (+ @a 22)))] @a)
2"forced a\n"(let [[positional kwargs] (split-with (complement keyword?) [1 2 3 :foo 4 :bar 5]) arg-map (apply hash-map kwargs)] [positional arg-map])
[(1 2 3) {:bar 5, :foo 4}]
(let [[_ year month day] (re-find #"(\d{4})-(\d{2})-(\d{2})" "2011-02-03")] [year month day])
["2011" "02" "03"]
(let [m {:a {:b {:c 0}}}] [(get-in m [:a :b :c]) (get-in m [:a :b]) (get-in m [:a]) (get-in m [])])
[0 {:c 0} {:b {:c 0}} {:a {:b {:c 0}}}]
(let [f #(fn [& y] (apply % (reverse y)))] ((f map) (replicate 3 (range 3)) ((f partial) inc map)))
((1 2 3) (1 2 3) (1 2 3))
(let [wtf (iterate macroexpand-1 '(->> . :__ (->> @two (->> args))))] (= (nth wtf 5) (nth wtf 9)))
true(let [[a [_ & b]] (split-with #(not= 3 %) [1 2 3 3 5 3 6])] (concat a b))
(1 2 3 5 3 6)
(let [form '(add 1 2 3 4 5)] (reduce (fn [f x] (list f x)) (first form) (next form)))
(((((add 1) 2) 3) 4) 5)
(defn foo [x] (let [add-5? (fn [y] (if (> x 8) (conj y 5) y))] (-> [3] (conj 4) add-5?)))
#'user/foo
(let [m {:a [1 2]} k (apply key m) vs (apply val m)] (for [v vs] (hash-map k v)))
({:a 1} {:a 2})
(macroexpand-1 '(let [{[x & y] :items} {:hp 100, :items '[sword bread apple hammer], :mana 10}] [x y y]))
(let [{[x & y] :items} {:hp 100, :mana 10, :items (quote [sword bread apple hammer])}] [x y y])
(let [a #{:a :b} b #{:c :a}] (clojure.set/difference (clojure.set/union a b) (clojure.set/intersection #{:a :b} #{:c :a})))
#{:b :c}
(defn foo [#^"[[J" x] (loop [a (long 0)] (recur (aget (let [#^"[J" y (aget x 1)] y) 1))))
#'user/foo
(let [atm (atom 100) coll {:a atm, :b atm}] (do (swap! atm inc) (reset! (:a coll) 5) @(:b coll)))
5(let [s #{:a :b :c :d} i (rand-int (count s)) e (nth (seq s) i)] [e (disj s e)])
[:b #{:a :c :d}]
(let [a :one b a a :two c a] (str "b is " b " and c is " c))
"b is :one and c is :two"(let [x (partition 3 (range 10))] (concat (list (ffirst x) (first (last x))) (list (last (first x)) (last (last x)))))
(0 6 2 8)
(let [m1 {:a 2, :b 3} m2 {:b 3, :c 4}] (select-keys m1 (clojure.set/intersection (set (keys m1)) (set (keys m2)))))
{:b 3}
(let [{:keys [a b z], :or {z 10}, :as opts} {:a 1, :b 2, :c 3}] [a b z opts])
[1 2 10 {:a 1, :b 2, :c 3}]
(let [x '({:_id "blah", :old_id 375} {:_id "hello", :old_id 376})] (apply zipmap (map #(map % x) [:old_id :_id])))
{375 "blah", 376 "hello"}
(let [m1 {:x 1, :y 2} m2 {:x 2, :y 2}] (remove #(= (m1 %) (m2 %)) (keys m1)))
(:x)
(let [comparize #(%1 (compare %2 %3) 0)] (map (partial comparize < [1 2]) [[1] [1 2] [1 2 3]]))
(false false true)
(let [n 10 f (apply partial (concat (take (dec n) (repeat partial)) [+]))] (reduce #(%1 %2) f (range n)))
45(let [s [1 2 3 4 5 4 5 6 7 6 7 8]] (map > s (cons 0 s)))
(true true true true true false true true true false true true)
(let [x1 (list "one" "two" "three") x2 (conj x1 "zero")] (every? #(apply identical? %) (map vector x1 (rest x2))))
true(first (remove #(> % 0.5) (repeatedly (fn [] (let [r (rand)] (print (str :print " " r " ")) r)))))
0.28462398575892744":print 0.28462398575892744 "(let [line "foo!bar@baz test" [nick more] (.split line "!" 2) [user host] (.split more "@" 3)] [nick user host])
["foo" "bar" "baz test"]
(letfn [(random-swap [coll] (let [[l r] (split-at (rand-int (count coll)) coll)] (concat r l)))] (nth (iterate random-swap (range 20)) 5))
(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19)
(let [coll (vector 1 2 3 4) seq-version (seq coll)] {:coll (conj coll 5), :seq (conj seq-version 5)})
{:coll [1 2 3 4 5], :seq (5 1 2 3 4)}
(defn swap!-old [a f & args] (let [old (atom nil)] (swap! a #(do (reset! old %) (apply f args)))))
#'user/swap!-old
(let [s "1 2 ;comment \n 3 ; more comment"] (rest (read-string (str "(do " s " \n)"))))
(1 2 3)
(let [m1 {:a 1, :b 4} m2 {:a 1, :b 2, :extra 3}] (= m1 (select-keys m2 (keys m1))))
false(let [oldm {:a 1, :b 2} newm {:a 1, :b 3}] (remove #(= (oldm %) (newm %)) (keys oldm)))
(:b)
(let [[a b] (split-with (partial not= 3) [5 4 3 2 1 2 3 4 5])] (concat a (rest b)))
(5 4 2 1 2 3 4 5)
(let [dissoc-in (fn [m ks] (update-in m (butlast ks) dissoc (last ks)))] (dissoc-in {:a {:b {:c 1}}} [:a :b :c]))
{:a {:b {}}}
(let [+ (fn [a b] (if (odd? a) (+ a b) (- a b)))] [(+ 1 2) (+ 2 2)])
[3 0]
(defn mins [xs] (let [m (apply min xs)] (for [x (map-indexed vector xs) :when (= m (second x))] (first x))))
#'user/mins
((fn [m] (let [e (empty m) res (map identity m)] (into e res))) (sorted-map :a 1 :b 2 :c 3))
{:a 1, :b 2, :c 3}
(defn foobar [f0] (let [f1 (apply str (take (.lastIndexOf f0 ".") f0))] (apply str (drop (inc (.lastIndexOf f1 "\\")) f1))))
#'user/foobar
(let [Length 20 Pad \- Name (vec "TEttinger")] (apply str (map #(get Name %1 %2) (range) (repeat Length Pad))))
"TEttinger-----------"(let [[foo bar _ _ & baz] [1 2 3 4 5 6 7 8 9 10]] [foo bar baz])
[1 2 (5 6 7 8 9 10)]
(let [keywordize (fn [m] (into (empty m) (for [[key val] m] [(keyword key) val])))] {'some-symbol 1, "some-string" 2, 'symbol.with/namespace 3})
{"some-string" 2, some-symbol 1, symbol.with/namespace 3}
(let [a (delay (do (println "forced a") (+ 1 1))) b (delay (do (println "forced b") (+ @a 22)))] nil)
nil(let [a (+ 23 24)] (doseq [b (range 24 48)] (print (mod (min (- a b) (- b a)) 24))))
nil"12345678910111213141516171819202122230"(defmacro defn' [name arglist & body] `(defn ~name ~arglist (let [~'&args ~(into {} (map (juxt keyword identity) arglist))] ~@body)))
#'user/defn'
(let [a (delay (do (println "forced a") (+ 1 1))) b (delay (do (println "forced b") (+ @a 22)))] @b)
24"forced b\nforced a\n"(let [f (fn lz-rec-step [s] (lazy-seq (if (seq s) (cons (first s) (lz-rec-step (rest s))) [])))] (take 5 (f (range 10))))
(0 1 2 3 4)

