(defn subvec? [a b] (some #(= % b) (partition (count b) 1 a)))
#'user/subvec?
(defn sum-of-squares [s] (reduce (fn [a b] (+ a (* b b))) 0 s))
#'user/sum-of-squares
(let [{:keys [a b c]} {:a 0, :b 1, :c 2}] [a b c])
[0 1 2]
((fn [a b] (= b (take (count b) a))) [1 2] [1 2 3])
false
((fn [{f :fn, a :arg}] (f a)) {:arg 5, :fn #(+ % %)})
10
((fn [& {:keys [a b]}] (vector a b)) :a 1 :b 2 :c 'nope)
[1 2]
((comp first filter) (fn [a] (prn 1) (= a 2)) [1 2 3 4])
2
"1\n1\n1\n1\n"
(reduce (fn [a [k v]] (assoc a k (Integer/parseInt v))) {} {:a "1", :b "2"})
{:a 1, :b 2}
(map first (take 10 (iterate (fn [[a b]] [b (+ a b)]) [0 1])))
(0 1 1 2 3 5 8 13 21 34)
(let [[a b c :as d] [1 2 3 4]] [a b c d])
[1 2 3 [1 2 3 4]]
(defn fibo [] (map first (iterate (fn [[a b]] [b (+ a b)]) [0N 1N])))
#'user/fibo
(let [[a b :as m] [1 2 3 4 5 6]] [a b m])
[1 2 [1 2 3 4 5 6]]
(let [a {:a []} c [{:a 2} {:a 3}]] (apply merge-with conj a c))
{:a [2 3]}
(take 50 (map first (iterate (fn [[a b]] [b (+ a b)]) [0 1])))
(0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 2178309 3524578 5702887 9227465 14930352 24157817 39088169 63245986 102334155 165580141 267914296 433494437 701408733 1134903170 1836311903 2971215073 4807526976 7778742049)
(doseq [a [1 2] b '[x y z w]] (println a "." b))
nil
"1 . x\n1 . y\n1 . z\n1 . w\n2 . x\n2 . y\n2 . z\n2 . w\n"
((fn [a b & [more]] [a b more]) 1 2 {:a 1, :b 2})
[1 2 {:a 1, :b 2}]
(map (fn [a b] {:in a, :out b}) [1 2 3] [4 5 6])
({:in 1, :out 4} {:in 2, :out 5} {:in 3, :out 6})
(let [[a b :as v] [1 2 3 4 5]] {:a a, :v v})
{:a 1, :v [1 2 3 4 5]}
(apply (fn [& [a b c & z]] [a b c z]) (range 10))
[0 1 2 (3 4 5 6 7 8 9)]
((fn ([a b c & more] :first) ([a b c] :second)) :a :b :c)
:second
(map (fn [a] ({[] true} a false)) [() nil [] [1 2 3] (list 1 2 3)])
(true false true false false)
((fn [& {:keys [a b]}] (vector a b)) {:a 1, :b 2, :c 'nope})
[1 2]
((fn [a b & c] [a b c]) 1 2 3 4 5 6)
[1 2 (3 4 5 6)]
(letfn [(foo [& {a :a, b :b}] [a b])] (foo :a 1 :b 2))
[1 2]
(for [a [[1 2 3] [4 5 6] [7 8 9]] i a] i)
(1 2 3 4 5 6 7 8 9)
(defn fibb [] (map first (iterate (fn [[a b]] [b (+ a b)]) [0N 1N])))
#'user/fibb
(let [[a :as [b :as [c & [d]]]] [1 2]] [a b c d])
[1 1 1 2]
(reduce (fn [a f] (f a)) 1 [- (partial + 3) (partial * 10)])
20
(let [{:strs [a b c]} {"a" 0, "b" 1, "c" 2}] [a b c])
[0 1 2]
((fn [a b & c] [a b c]) 1 2 :name "steve" :age "paul")
[1 2 (:name "steve" :age "paul")]
(def fibs (map second (iterate (fn [[a b]] [b (+ a b)]) [0 1])))
#'user/fibs
(binding [*print-dup* true] (letfn [(foo [^Long a] (* a 2))] (-> foo meta pr)))
nil
"nil"
(let [[x & {:keys [a b]}] [0 :a 1 :b 2]] [x a b])
[0 1 2]
(reduce (fn [a b] (+ (a 1) (b 1))) '([:a 1] [:b 2]))
3
(loop [[a & r] (range)] (if (= a 4) (first r) (recur (rest r))))
5
(let [[a b] (int-array [1 2]) _ (println (str "a=" a " b=" b))])
nil
"a=1 b=2\n"
(defn otherfn [a b c & args] (apply println (conj args c b a)))
#'user/otherfn
(apply (fn [a b & r] [a b (take 3 r)]) (iterate inc 0))
[0 1 (2 3 4)]
(mapcat (fn [[a b]] (vector (inc a) b)) (partition 2 [1 2 3 4]))
(2 2 4 4)
(let [[a b] (re-matches #"(\d+) (\d+)" "12 34")] (prn a) (prn b))
nil
"\"12 34\"\n\"12\"\n"
(defn emit-bash-form [a] (let [c (class a)] (cond (= c java.lang.Integer) "int" :else nil)))
#'user/emit-bash-form
((fn [[a & r]] (if (= a 4) (first r) (recur (rest r)))) (range))
5
((fn [a b] (= b (take (count b) a))) [1 2 3] [1 2])
true
(def fib (map first (iterate (fn [[a b]] [b (+ a b)]) [0 1])))
#'user/fib
(take 15 (map first (iterate (fn [[a b]] [b (+ a b)]) [0 1])))
(0 1 1 2 3 5 8 13 21 34 55 89 144 233 377)
(let [[a b c] [1 2 3] b (str b)] (list a b c))
(1 "2" 3)
((fn [[a b c]] (println "a" a "b" b "c" c)) [1 2 3])
nil
"a 1 b 2 c 3\n"
(map second (take 10 (iterate (fn [[a b]] [b (+ a b)]) [0 1])))
(1 1 2 3 5 8 13 21 34 55)
(let [a (atom 1) f '(swap! a inc)] `(if ~f (~f)))
(if (swap! a inc) ((swap! a inc)))
(def fib (map (first (iterate (fn [[a b]] [b (+ a b)]) [0 1]))))
#'user/fib