(let [v [1 2 3]] (for [n (range (count v))] (take (inc n) v)))
((1) (1 2) (1 2 3))
(let [a (atom 1) f '(swap! a inc)] `(if ~f (~f)))
(if (swap! a inc) ((swap! a inc)))
(defn enumerate [coll i] (lazy-seq (cons [i (first coll)] (enumerate (rest coll) (inc i)))))
#'user/enumerate
(map (fn this [x] (if (sequential? x) (map this x) (inc x))) [[2] [[3]]])
((3) ((4)))
(defn foo [n] (loop [i 1] (if (< i n) (recur (inc i)) i)))
#'user/foo
(let [f #(inc %)] (reductions #(%2 %1) 1 [f f f f]))
(1 2 3 4 5)
(-> {} (assoc :k1 'v1) (assoc :k2 [0 1 2 3]) (update-in [:k2 0] inc))
{:k1 v1, :k2 [1 1 2 3]}
(map-indexed #(if (> 3 %1) (inc %2) %2) [5 4 6 3 4])
(6 5 7 3 4)
(loop [[a b] (range)] (if (= 10 a) b (recur (map inc [a b]))))
11
(reduce + (for [x (range 20)] (/ (reduce * 1.0 (range 1 (inc x))))))
2.7182818284590455
(let [a (atom 0)] (second (map (fn [_] (swap! a inc)) (range 50))) @a)
32
(let [state (atom {:plots [[1 2] [1 5]]})] (update-in @state [:plots 0 1] inc))
{:plots [[1 3] [1 5]]}
(let [s "a/b/c/d/e"] (map #(subs s 0 (inc %)) (range 0 (count s))))
("a" "a/" "a/b" "a/b/" "a/b/c" "a/b/c/" "a/b/c/d" "a/b/c/d/" "a/b/c/d/e")
(let [m (transient {})] (doseq [i (range 10)] (assoc! m i (inc i))) (count m))
8
(defn prange ([] (prange 1)) ([n] (prn 'Realized' n) (cons n (lazy-seq (prange (inc n))))))
#'user/prange
(take 20 (let [a (iterate inc 1)] (for [x a y a] [x y])))
([1 1] [1 2] [1 3] [1 4] [1 5] [1 6] [1 7] [1 8] [1 9] [1 10] [1 11] [1 12] [1 13] [1 14] [1 15] [1 16] [1 17] [1 18] [1 19] [1 20])
(take-while #(>= % 0) (iterate #(.indexOf "a,bcde,f,gh" (int \,) (inc %)) 0))
(0 1 6 8)
(let [chunksize (atom 0)] (first (map #(do % (swap! chunksize inc)) (range 100))) @chunksize)
32
(for [[k v] (partition 2 '(:a 1 :b 2 :c 3))] [(inc v) k])
([2 :a] [3 :b] [4 :c])
(-> {:a {:b 4}, :c {:d 3}} (update-in [:a :b] inc) (update-in [:c :d] dec))
{:a {:b 5}, :c {:d 2}}
(map (juxt class pr-str) [(list 1 2 3) (map inc [0 1 2]) (cons 1 ())])
([clojure.lang.PersistentList "(1 2 3)"] [clojure.lang.LazySeq "(1 2 3)"] [clojure.lang.Cons "(1)"])
(let [m {:a 1, :b 2, :c 3}] (zipmap (keys m) (map inc (vals m))))
{:a 2, :b 3, :c 4}
(let [m {:a 1, :b 2, :c 3}] (zipmap (keys m) (map inc (vals m))))
{:a 2, :b 3, :c 4}
(loop [cnt 0] (if-not (= cnt 3) (do (println cnt) (recur (inc cnt))) (println "done")))
nil
"0\n1\n2\ndone\n"
(for [x [:x1 :x2 :x3 :x4 :x5 :x6] :let [i 0]] (assoc {} x (inc i)))
({:x1 1} {:x2 1} {:x3 1} {:x4 1} {:x5 1} {:x6 1})
(let [a {:a (atom 0)}] (= a (do (swap! (:a a) inc) (println a) a)))
true
"{:a #object[clojure.lang.Atom 0x703dee58 {:status :ready, :val 1}]}\n"
(let [myfn (fn myfn [x] (lazy-seq (cons x (myfn (inc x)))))] (take 5 (myfn 1)))
(1 2 3 4 5)
(let [f 'inc arg (with-meta '(inc 1) {:x 1})] (meta (second `(~f ~arg))))
{:x 1}
(defn pick [coll n] [(nth coll n) (concat (take n coll) (drop (inc n) coll))])
#'user/pick
(update {} :foo (fn [foo] (-> foo (update-in [:bar :quux] (fnil inc 0)) (assoc-in [:string] "string!"))))
{:foo {:bar {:quux 1}, :string "string!"}}
(loop [a 1 b 2] (when (< b 5) (print b) (recur b (inc a))))
nil
"223344"
(let [m {:a 10, :b 20}] (reduce #(update-in %1 [%2] inc) m (keys m)))
{:a 11, :b 21}
(into {} (map (fn [[k v]] [(dec k) (inc v)]) {1 2, 3 4, 5 6}))
{0 3, 2 5, 4 7}
(for [x (iterate inc 0) :while (< x 10) y [x] :when (even? y)] y)
(0 2 4 6 8)
(map #(into (empty %) (map inc %)) '[[0 1 2] (0 1 2)])
([1 2 3] (3 2 1))
(reduce (fn [totals x] (update totals x (fnil inc 0))) {} [:a :b :a :c :a])
{:a 3, :b 1, :c 1}
(apply hash-map (mapcat #(vector (first %) (-> % second inc)) {:a 1, :b 2}))
{:a 2, :b 3}
(let [f (fn [x & y] (first (drop 1e3 y)))] (apply f (iterate inc 0)))
1001
(take 10 (map first (iterate (fn [[t n]] [(+ t n) (inc n)]) [1 2])))
(1 3 6 10 15 21 28 36 45 55)
(let [r (:repeat {:repeat 1} 0)] (if (< r 2) [r] (range 1 (inc r))))
[1]
((fn my-plus [x y] (if (zero? x) y (my-plus (dec x) (inc y)))) 10 20)
30
(map #(vector %1 %2 %3) (iterate inc 0) [:a :b :c] [:a :a :a])
([0 :a :a] [1 :b :a] [2 :c :a])
(def tmp (next (cons 1 (iterate #(do (println (str %1)) (flush) (inc %1)) 1))))
#'user/tmp
(let [state (atom {:plots [[1 2] [1 5]]})] (swap! state update-in [:plots 0 1] inc))
{:plots [[1 3] [1 5]]}
(let [nth-arg (fn [n & args] (nth args n))] (apply nth-arg 99 (iterate inc 44)))
143
(every? (fn [[a b]] (== (inc a) b)) (partition 2 1 [4 5 5 7]))
false
(let [a (atom 0) foo (constantly (do (swap! a inc) :hi))] (foo) (foo) (foo) @a)
1
(let [a (atom 4)] (swap! a inc) (prn a) (swap! a + 10) (prn a))
nil
"#object[clojure.lang.Atom 0xf71769d {:status :ready, :val 5}]\n#object[clojure.lang.Atom 0xf71769d {:status :ready, :val 15}]\n"
(->> [2 5 4 1 3 6] (drop 2) (take 3) (map inc) (reduce +))
11
(doseq [[i e] (map vector (iterate inc 0) '[foo bar baz])] (println i e))
nil
"0 foo\n1 bar\n2 baz\n"