(def def "Pfft, can't take the value of a macro, eh?")
#'user/def
(map #(let [a %] (into {} [[1 2]])) [:a :b :c])
({1 2} {1 2} {1 2})
(let [ks '(a b)] (into {} (map (juxt keyword identity) ks)))
{:a a, :b b}
(doseq [x (reductions conj [] '(a b c d))] (println x))
nil
"[]\n[a]\n[a b]\n[a b c]\n[a b c d]\n"
(map hash-set '(a b) '(c d) '(e f))
(#{a c e} #{b d f})
(defn f [& [a b & c :as argv]] (println argv))
#'user/f
(def a (doall (for [n (range 2)] (do (println n) n))))
#'user/a
"0\n1\n"
(let [{:keys [a b]} {:a 2, :b 3, :c 9}] b)
3
(apply conj [] '({:a a, :b b} {:c c, :d d}))
[{:a a, :b b} {:c c, :d d}]
(#(cons (last %) (butlast %)) '(a b c d))
(d a b c)
(letfn [(strictly-ascending [vals _yes _no] (if (every? (fn [[a b]] (< a b)) (partition 2 1 vals)) _yes _no))] (strictly-ascending [1 2 3] :yes :no))
:yes
((fn [a b & args] (into {} (map (fn [[x y]] [(a x) (b y)]) (partition 2 args)))) identity inc :a 1 :b 2 :c 3)
{:a 2, :b 3, :c 4}
((fn a [m n] (cond (zero? m) (inc n) (zero? n) (recur (dec m) 1) :else (recur (dec m) (a m (dec n))))) 3 1)
13
((fn foo [{:keys [a b c]} & {:keys [opt1 opt2]}] [a b c opt1 opt2]) {:a 1, :b 2, :c 3} :opt1 4 :opt2 5)
[1 2 3 4 5]
(let [coll '(1 3 2 5 4 7)] (last (keep-indexed (fn [i [a b]] (when (< a b) (inc i))) (partition 2 1 coll))))
5
(let [start {"name" "databases", "columns" ["name"], "values" [["testdb"] ["mydb"]]}] (map (fn [vcoll] (map (fn [a b] {(keyword a) b}) (start "columns") vcoll)) (start "values")))
(({:name "testdb"}) ({:name "mydb"}))
(map (fn [[a b _ _ e & _]] (vector a b e)) [[1 2 3 4 5 6] [-1 -2 -3 -4 -5 -6]])
([1 2 5] [-1 -2 -5])
(let [yielder (fn [s] (let [a (atom s)] (fn [] (first (swap! a next))))) test (yielder [:conn1 :conn2 :conn3 :conn4])] (for [_ (range 10)] (test)))
(:conn2 :conn3 :conn4 nil nil nil nil nil nil nil)
(let [start {"name" "databases", "columns" ["name"], "values" [["testdb"] ["mydb"]]}] (mapcat (fn [vcoll] (map (fn [a b] {(keyword a) b}) (start "columns") vcoll)) (start "values")))
({:name "testdb"} {:name "mydb"})
(map (fnil clojure.string/trim "") [" a " "b" nil "d "])
("a" "b" "" "d")
(let [a '(1 2 3) b '(4 5 6)])
nil
(for [b '(1 2 3) :let [a 1]] (println b))
(nil nil nil)
"1\n2\n3\n"
(let [L (with-meta '(a b) {:foo :bar})] (type (pop L)))
clojure.lang.PersistentList
(when-let [{:keys [foo]} {:bar nil}] (println "This seems like a bug"))
nil
"This seems like a bug\n"
(defn incv "Like inc but returns a vector." [x] [(inc x)])
#'user/incv
(defprotocol Seqable [coll] (seq [coll] "Returns a seq on the collection"))
{:methods #{#object [clojure.lang.MultiFn 0x21c29f46 "clojure.lang.MultiFn@21c29f46"] #object [clojure.lang.MultiFn 0x2f05750e "clojure.lang.MultiFn@2f05750e"]}, :name user/Seqable, :ns #object [sci.impl.vars.SciNamespace 0x37a47b18 "user"], :sigs {:coll {:arglists nil, :doc nil, :name coll}, :seq {:arglists ([coll]), :doc "Returns a seq on the collection", :name seq}}}
(let [as [0 1 2 3] bs [9 8 7 6]] (doseq [a as b bs] (println (format "a %d and b %d" a b))))
nil
"a 0 and b 9\na 0 and b 8\na 0 and b 7\na 0 and b 6\na 1 and b 9\na 1 and b 8\na 1 and b 7\na 1 and b 6\na 2 and b 9\na 2 and b 8\na 2 and b 7\na 2 and b 6\na 3 and b 9\na 3 and b 8\na 3 and b 7\na 3 and b 6\n"
(defn update-vals [a b c d e f] [(+ 1 a) (+ 1 b) (+ 1 c) (+ 1 d) (+ 1 e) (+ 1 f)])
#'user/update-vals
(let [a #(apply str (flatten %)) p partition R rand-nth n #(a (R (mapcat p [1 2 3] %&))) v #(n "aioeu" "iaaiaa")] (a [(n "STKNYPKLGVZ" "GlThShNyFtCh" "ZvrCthShrMycTch") (for [_ " "] [(v) (n "lpstnkgxzv" (concat [(R '[h gl gr nd]) (v)] "rnthggghtsltrkkhshng") "ghnlok")])]))
"Cthaatsig"
(defn cross [vec-a vec-b] (let [a (cycle vec-a) b (cycle vec-b)] (map (fn [ind] (- (* (nth a (+ ind 1)) (nth b (+ ind 2))) (* (nth a (+ ind 2)) (nth b (+ ind 1))))) '(0 1 2))))
#'user/cross
(let [filter-first (fn [pred s] (let [[a b] (split-with pred s)] (concat a (next b))))] (filter-first #(= 1 %) '(9 6 1 3 1)))
(6 1 3 1)
(defn swap!* [a f & args] (let [ret (atom nil)] (apply swap! a (fn [x & args] (reset! ret x) (apply f x args)) args) @ret))
#'user/swap!*
(let [yield (fn [seq] (let [a (atom (cons nil seq))] (fn [] (first (swap! a next))))) test (yield [1 2 3 4])] [(test) (test) (test) (test)])
[1 2 3 4]
(let [empty (Object.)] ((fn [as bs] (map (fn [a b] (if (= b empty) a b)) as (concat bs (repeat empty)))) ["" "A" "B"] [1 2]))
(1 2 "B")
(defn cartes4 [a b & more] (let [so-far (for [x a y b] [x y])] (if more (recur so-far (first more) (next more)) (map flatten so-far))))
#'user/cartes4
(let [decide (fn [xs a b] (if (seq xs) (a xs) b))] [(decide (range 1 6) (partial apply *) 42) (decide '() (partial apply *) 42)])
[120 42]
(let [yielder (fn [s] (let [a (atom s)] (fn [] (first (swap! a next))))) test (yielder (cycle [:conn1 :conn2 :conn3 :conn4]))] (for [_ (range 10)] (test)))
(:conn2 :conn3 :conn4 :conn1 :conn2 :conn3 :conn4 :conn1 :conn2 :conn3)
(->> (map (fn [a] (a)) (list #(/ 1 1) #(/ 1 0) #(/ 1 2))) (cons 123) (drop-while #(= % 123)) first)
1
(map #(list (first %) (last %)) '([a b] [c d]))
((a b) (c d))
(let [xs '[a b c d]] (map list xs (rest xs)))
((a b) (b c) (c d))
(let [L (with-meta '(a b) {:foo :bar})] (meta (conj L 'c)))
{:foo :bar}
(if-let [[a b c d e f] (concat (range 5) [nil])] f)
nil
(let [nums [1 2 3 4 5] [a b c] nums] c)
3
(format "%s" "is there no there no (format a b) in clojurescript?")
"is there no there no (format a b) in clojurescript?"
((fn [x] (conj (butlast x) (last x))) '(a b c d))
(d a b c)
(meta (into '#^{:some :meta} {e f} '{a b, c d}))
{:some :meta}
((fn [& [a b :as all]] [b all]) 1 2 3 4)
[2 (1 2 3 4)]
(if (every? zero? (repeatedly 3 #(rand-int 2))) "Three in a row!")
nil
(let [L (with-meta '(a b) {:foo :bar})] (meta (cons 'c L)))
nil
((fn [& [a b c]] c) 1 2 3 4 5 6)
3