(let [i (atom 0)] {:filter (first (filter #(do (swap! i inc) (odd? %)) (range 25))), :i i})
{:filter 1, :i #object [clojure.lang.Atom 0x710d8e8f {:status :ready, :val 25}]}
(let [a [1 2 3] _ (prn a) b (map inc a) _ (prn b)] 'foo)
foo
"[1 2 3]\n(2 3 4)\n"
(reduce (fn [m [k f]] (assoc m k (f m))) {:a 1} [[:b #(-> % :a inc)]])
{:a 1, :b 2}
(loop [myvec [1 2 3] outint 0] (if (= 0 (count myvec)) outint (recur (rest myvec) (inc outint))))
3
(clojure.walk/postwalk #(if (number? %) (inc %) %) (sorted-map-by (comp - compare) 1 2 3 4 5 6))
{2 3, 4 5, 6 7}
(reduce (fn [freqs elem] (assoc freqs elem (inc (get freqs elem 0)))) {} [:a :a :b :c :a :b])
{:a 3, :b 2, :c 1}
(let [v [0 1 2 3] i 2] (apply conj (subvec v 0 i) (nthnext v (inc i))))
[0 1 3]
((fn f [c & args] (if (seq args) (recur (inc c) (rest args)) c)) 0 'a 'b 'c)
3
(letfn [(foo [f m] (into {} (for [[k v] m] [k (f v)])))] (foo inc {:a 1, :b 2}))
{:a 2, :b 3}
(take (inc (count (take-while odd? [3 3 3 9 7 8 4]))) [3 3 3 9 7 8 4])
(3 3 3 9 7 8)
(take-while #(> % 1) (iterate (fn [n] (if (even? n) (/ n 2) (inc (* n 3)))) 9))
(9 28 14 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2)
(letfn [(updown [n] (if (odd? n) (inc n) (dec n)))] (map (comp updown updown) [1 2 3 4 5]))
(1 2 3 4 5)
(let [v [0 1 2] i 1] (reduce conj (subvec v 0 i) (subvec v (inc i) (count v))))
[0 2]
(let [apply-if (fn [pred func val] (if (pred val) (func val) val))] (map (partial apply-if odd? inc) (range 10)))
(0 2 2 4 4 6 6 8 8 10)
(defn get-it [] (repeatedly (inc (rand-int 4)) #(case (rand-int 5) (0 1) 'get (2 3) ''get 4 (get-it))))
#'user/get-it
(reduce (fn [[state result] item] [(inc state) (conj result (+ state item))]) [0 []] [1 2 3 4 5])
[5 [1 3 5 7 9]]
(loop [l [] val 0] (if (= (count l) 5) (println l) (recur (conj l val) (inc val))))
nil
"[0 1 2 3 4]\n"
(type (loop [m {} i 0] (if (< i 100) (recur (assoc m (str i) i) (inc i)) m)))
clojure.lang.PersistentHashMap
(let [x (atom 1) y x] (print "x:" x "y:" y) (swap! y inc) (print "x:" x "y:" y))
nil
"x: #object[clojure.lang.Atom 0x6d06f034 {:status :ready, :val 1}] y: #object[clojure.lang.Atom 0x6d06f034 {:status :ready, :val 1}]x: #object[clojure.lang.Atom 0x6d06f034 {:status :ready, :val 2}] y: #object[clojure.lang.Atom 0x6d06f034 {:status :ready, :val 2}]"
(let [i (atom 0)] {:filter (first (filter #(do (swap! i inc) %) (apply hash-map (range 100)))), :i i})
{:filter [0 1], :i #object [clojure.lang.Atom 0x437ff565 {:status :ready, :val 1}]}
(with-in-str "(def a 1) (inc a)" (doall (take-while (complement #{::done}) (repeatedly #(read *in* false ::done)))))
((def a 1) (inc a))
(let [apply-if (fn [pred func] (fn [val] (if (pred val) (func val) val)))] (map (apply-if odd? inc) (range 10)))
(0 2 2 4 4 6 6 8 8 10)
(map #(into (empty %) (map inc %)) [[1 2 3] '(1 2 3) #{1 2 3}])
([2 3 4] (4 3 2) #{2 3 4})
(defn foo ([a] {:pre [(pos? a)]} (inc a)) ([a b] {:pre [(= 15 (+ a b))]} (- a b)))
#'user/foo
(map first (reductions (fn [[prev state] item] [(+ state item) (inc state)]) [nil 0] [1 2 3 4 5]))
(nil 1 3 5 7 9)
(into [] (map (fn [m] (assoc m :a (inc (get m :a)))) [{:a 1, :b 2} {:a 3, :b 4}]))
[{:a 2, :b 2} {:a 4, :b 4}]
(let [m {:a 1, :b 2, :c 3}] (into (empty m) (map (juxt key (comp inc val)) m)))
{:a 2, :b 3, :c 4}
(letfn [(drop-nth [index coll] (concat (take index coll) (drop (inc index) coll)))] (drop-nth 2 [1 2 3 4]))
(1 2 4)
(->> (filter odd? (map #(* % %) (iterate inc 1))) (take-while #(< % 10000000000)) (reduce +))
166666666650000
(type (loop [m {} i 0] (if (< i 10) (recur (assoc m (str i) i) (inc i)) m)))
clojure.lang.PersistentHashMap
(let [base 17] (map #(inc (read-string (apply str "0" (drop-last (Integer/toString (dec %) base))))) (range 1 100)))
(1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6)
(let [i (atom 0)] {:filter (first (filter #(do (swap! i inc) (odd? %)) (range 100))), :i i})
{:filter 1, :i #object [clojure.lang.Atom 0x339d04c3 {:status :ready, :val 32}]}
(let [i (atom 0)] {:filter (first (filter #(do (swap! i inc) (odd? %)) (range 5))), :i i})
{:filter 1, :i #object [clojure.lang.Atom 0x48a30554 {:status :ready, :val 5}]}
(let [a (atom 0) o (reify Object (toString [this] (swap! a inc) (str @a)))] [(str o) (str o)])
["1" "2"]
(take 10 (map first (iterate (fn [[t n]] (let [i (inc n)] [(+ t i) i])) [1 1])))
(1 3 6 10 15 21 28 36 45 55)
(let [foo [1 2 3 4]] (->> (map #(= %1 (inc %2)) foo (rest foo)) (every? true?)))
false
(map #(when-not (= %2 %3) [%1 %2 %3]) (iterate inc 0) [:a :b :c] [:a :a :a])
(nil [1 :b :a] [2 :c :a])
(let [a (atom 0)] (clojure.walk/postwalk (fn [x] (swap! a inc) x) '(dotimes [i 5] (println "Hello"))) @a)
8
(reductions #(if (= %2 42) (reduced %1) (inc %1)) (iterate #(bit-xor % (bit-shift-left 1 (rand-int 8))) 12))
(12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133...
(apply str (sequence (comp (map int) (filter even?) (map inc) (map char)) "hello, this is gibberish from a transducer"))
"imm-!ui!!ccsi!gs!!usoes"
(loop [l '() val 0] (if (= (count l) 5) (println l) (recur (cons val l) (inc val))))
nil
"(4 3 2 1 0)\n"
(let [a (atom 0) action (delay (swap! a inc)) f #(force a)] [(f) (f) (f)])
[#object [clojure.lang.Atom 0x319f4626 {:status :ready, :val 0}] #object [clojure.lang.Atom 0x319f4626 {:status :ready, :val 0}] #object [clojure.lang.Atom 0x319f4626 {:status :ready, :val 0}]]
(defn ab [] (fn [x] (let [a (atom 0)] (if (= x :inc) (swap! a inc) (swap! a dec)) @a)))
#'user/ab
(let [input ">>><<v^"] (count (distinct (reduce (fn [[latest & others :as houses] dir] (conj houses (condp = dir \< (update-in latest [0] dec) \> (update-in latest [0] inc) \^ (update-in latest [1] inc) \v (update-in latest [1] dec)))) '([0 0]) input))))
5
(let [pred #{4} coll (range 0 10 2)] (reduce #(if (pred %2) (reduced %1) (inc %1)) 0 coll))
2
((fn weird-shit [n] (if (even? n) (partition 2 (range 1 (inc n))) (concat (weird-shit (dec n)) [[(dec n) n]]))) 16)
((1 2) (3 4) (5 6) (7 8) (9 10) (11 12) (13 14) (15 16))
(let [last-nth (fn [coll n] (nth coll (- (count coll) n 1)))] (= (last-nth (map inc (range 3)) 2) 1))
true
(let [f #(fn [& y] (apply % (reverse y)))] ((f map) (replicate 10 (range 10)) ((f partial) inc map)))
((1 2 3 4 5 6 7 8 9 10) (1 2 3 4 5 6 7 8 9 10) (1 2 3 4 5 6 7 8 9 10) (1 2 3 4 5 6 7 8 9 10) (1 2 3 4 5 6 7 8 9 10) (1 2 3 4 5 6 7 8 9 10) (1 2 3 4 5 6 7 8 9 10) (1 2 3 4 5 6 7 8 9 10) (1 2 3 4 5 6 7 8 9 10) (1 2 3 4 5 6 7 8 9 10))
(reduce #(if (even? (% %2)) (update % %2 inc) %) [1 2 3 4 5 6 7] [1 2])
[1 3 3 4 5 6 7]
(let [funcs {:a inc, :b dec} values {:b 5, :a 10}] (into {} (for [[k f] funcs] [k (f (values k))])))
{:a 11, :b 4}