(defn utf8response "Returns a ring skeleton withheaders." [body] {:status 200, :headers {:content-type "text/html;charset=UTF-8", :character-encoding "UTF-8"}, :body body})
#'user/utf8response
(some #(and (= (first %) 'd) %) (iterate next '(a b c d e f)))
(d e f)
(let [{:keys [a b c], :as m} {:a 1, :b 2, :c 3}] (assoc m :a 3))
{:a 3, :b 2, :c 3}
(let [v '[a b c d e f]] (into (subvec v 0 2) (subvec v 3)))
[a b d e f]
(let [inputs '[[a b c] [d e f]]] (for [xs inputs x xs] (keyword x)))
(:a :b :c :d :e :f)
(let [x '(a b c)] (vector `(1 2 ~x 3) `(1 2 ~@x 3)))
[(1 2 (a b c) 3) (1 2 a b c 3)]
(for [[a b] (map vector [1 2 3 4] [5 6 7 8])] {:a a, :b b})
({:a 1, :b 5} {:a 2, :b 6} {:a 3, :b 7} {:a 4, :b 8})
((fn [[a b c d :as l]] (if (= 4 (count l)) d :no-d)) [1 2 3])
:no-d
(defn utf8response "Returns a ring skeleton withheaders." [body] {:status 200, :headers {"Content-Type" "text/html;charset=UTF-8", "Character-Encoding" "UTF-8"}, :body body})
#'user/utf8response
(let [items '[a b c]] (for [x items y items :when (not= x y)] [x y]))
([a b] [a c] [b a] [b c] [c a] [c b])
(reduce (fn [m [id x]] (assoc m id x)) {} (map list (range) '(a b c d)))
{0 a, 1 b, 2 c, 3 d}
(reduce #(str %1 (when (zero? (mod (count %1) 8)) \/) %2) "" "this is a long string")
"/this is/ a long/ string"
(every? #(apply (fn [x y] (and x y)) ((juxt string? empty?) %)) (list "" '(a b)))
false
(let [items '(a b c)] (reduce (fn [[i acc] x] [(inc i) (conj acc x)]) [0 []] items))
[3 [a b c]]
(let [foo "foo & bar"] (str foo " isn't even a problem here, but nrepl.el pukes on it"))
"foo & bar isn't even a problem here, but nrepl.el pukes on it"
(read-string "(TOP (S (NP (DT This)) (VP (VBZ is) (NP (DT a) (NN sentence))) (. .)))")
(TOP (S (NP (DT This)) (VP (VBZ is) (NP (DT a) (NN sentence))) (. .)))
(into {} (for [[k v] (group-by second '([a :a] [b :a] [c :b]))] [k (vec (map first v))]))
{:a [a b], :b [c]}
(let [items '[a b c]] (for [x items y items :while (not= x y)] #{x y}))
(#{a b} #{a c} #{b c})
(defmacro papply [f & args] `(apply ~f (map deref ~(vec (for [a args] `(future ~a))))))
#'user/papply
(let [a #(apply str (flatten %)) r repeatedly p partition N rand-nth n #(a (N (concat (repeat % "") (mapcat p [1 2 3] %&)))) v #(n 0 "aioeu" "iaai") w (fn [] (let [b (n 6 "!." "" "...") s [(n 0 "STKNYPKLG" "GlThShNyFt" "ZvrCth") (r (N [1 2]) #(do [(v) (n 9 (map str "'-" (r 2 v))) (n 0 (concat "lpstnkgx" [(N ["h" "gl" "gr" "nd"]) (v)]) "rlthggghtsltrkkhshng")]))]] [b (if (seq b) [" " s] [(n 3 ",") " " (. (a s) toLowerCase)])]))] (re-find #"[A-Z].+" (a [(r 10 w) "."])))
"Ftagg cthia'eaarl, gialtark. Kel kap."
(let [a #(apply str (flatten %)) r repeatedly p partition N rand-nth n #(a (N (concat (repeat % "") (mapcat p [1 2 3] %&)))) v #(n 0 "aioeu" "iaai") w (fn [] (let [b (n 6 "!." "" "...") s [(n 0 "STKNYPKLG" "GlThShNyFt" "ZvrCth") (r (N [1 2]) #(do [(v) (n 9 (map str "'-" (r 2 v))) (n 0 (concat "lpstnkgx" [(N ["h" "gl" "gr" "nd"]) (v)]) "rlthggghtsltrkkhshng")]))]] [b (if (seq b) [" " s] [(n 3 ",") " " (. (a s) toLowerCase)])]))] (re-find #"[A-Z].+" (a [(r 500 w) "."])))
"Zvro-iathiag, nyia'agg yai'agh! Kikhea git. Thark piaserk pohia'aig... Zvraip, tash kun. Nyi'oo zvrapail! Thiangiath ting, nyiaia ge'ung! Ctholtukh thal. Tep koxak! Tus... Purlaith! Sai'up ship, gandai'aip surliang, pairl... Tokaith ko-aigh cthalt nyo-ilt! Tits. Pakhut. Nai'iash zvreggegg thets, zvrek gleshin. Cthoggigh. Kiakol nyailtarl gairl, cthongia-og, naip shutairl nax, giligg cthelegl! Nyi...
(defn stateful-random [[^long s _]] (let [R bit-shift-right X bit-xor a (unchecked-long (+ s 0x9E3779B97F4A7C15)) b (* (X a (R a 30)) 0xBF58476D1CE4E5B9) b (* (X b (R b 27)) 0x94D049BB133111EB) o (X b (R b 31))] (print o) [a o]))
#'user/stateful-random
(defn zippedy-do-da [coll] (zipmap '[zippedy do dah zippedy day my oh my what a wonderful day] coll))
#'user/zippedy-do-da
(let [[k & ks :as keys] '[a b c d e]] {:k k, :ks ks, :keys keys})
{:k a, :keys [a b c d e], :ks (b c d e)}
(defn foo [a b c d e f g h i j k & args] (println (first args)))
#'user/foo
(let [a #(apply str (flatten %)) r repeatedly p partition N rand-nth n #(a (N (concat (repeat % "") (mapcat p [1 2 3] %&)))) v #(n 0 "aioeu" "iaai") w (fn [] (let [b (n 7 "!." "" "...") s [(n 0 "STKNYPKLG" "GlThShNyFt" "ZvrCth") (r (N [1 2]) #(do [(v) (n 9 (map str "'-" (r 2 v))) (n 0 (concat "lpstnkgx" [[(N ["h" "gl" "gr" "nd"]) (v)]]) "rlthggghtsltrkkhshng")]))]] [b (if (seq b) [" " s] [(n 3 ",") " " (. (a s) toLowerCase)])]))] (re-find #"[A-Z].+" (a [(r 500 w) "."])))
"Ke'uts, ftiashais paits tiathogle nots cthenits, guts yogh... Nyiap noth lex! Gerk. Yilt. Tiag... Kindo gi'ork kia'uth, sha'ipirk yaingogre zvraigh... Nyiang kia-eth shaigail, kaipo'ork, tep tu'ath nuk! Ket... Nyax su-iaparl kan, fturk, kai-ikh! Nia-ail! Gogh. Nyaishik nyong... Glurk. Zvrig. Yes... Nyandiaolt, shirlaig zvreno'iax! Kel liaggiax shi-egg shaixats... Le-airlang. Ftu'oghirk thax, cthe...
(letfn [(comp-map [ma mb] (reduce (fn [a [k v]] (and a (if (and (map? v) (map? (mb k))) (comp-map v (mb k)) (= v (mb k))))) true ma))] (comp-map {:a {:b 2, :c 3}} {:a {:b 2, :c 3}}))
true
(let [{a :a, b :b, :as all} {:a 1, :b 2, :c 3}] {:a a, :b b, :all all})
{:a 1, :all {:a 1, :b 2, :c 3}, :b 2}
(rand-nth ["You called a protocol method with the wrong arity" "Clojure/Lein fucked up the AOT compilation; run lein clean."])
"You called a protocol method with the wrong arity"
(defonce records (doseq [[name arglist] '{Foo [a b c], Bar [d e f]}] (eval `(defrecord ~name ~arglist))))
#'user/records
(doseq [x '({:user "a", :reps {:a 1, :b 2}})] (let [{a :user, rs :reps} x] (print (keys rs))))
nil
"(:a :b)"
(defn foo [#^"[[J" x] (loop [a (long 0)] (recur (aget (let [#^longs y (aget x 1)] y) 1))))
#'user/foo
(let [items '(a b c)] (reduce (fn [[i acc] x] [(inc i) (conj acc [x i])]) [0 []] items))
[3 [[a 0] [b 1] [c 2]]]
(apply str (sequence (comp (map int) (filter even?) (map inc) (map char)) "hello, this is gibberish from a transducer"))
"imm-!ui!!ccsi!gs!!usoes"
(let [v '[a b c d e]] (-> (subvec v 0 2) (conj 'X) (into (subvec v 2))))
[a b X c d e]
(let [{x :x, :keys [a b], :strs [c d], :syms [e f], :or {x 0}, :as m} {:a 1, :b 2, "c" 3, "d" 4, 'e 5, 'f 6}] [x a b c d e f])
[0 1 2 3 4 5 6]
(defn stateful-random [[^long s _]] (let [R bit-shift-right X bit-xor a (unchecked-long (+ s 0x9E3779B97F4A7C15)) b (unchecked-long (* (X a (R a 30)) 0xBF58476D1CE4E5B9)) b (unchecked-long (* (X b (R b 27)) 0x94D049BB133111EB)) o (X b (R b 31))] (print o) [a o]))
#'user/stateful-random
(doseq [[[a b] [c d]] (map list {:1 1, :2 2} {:3 3, :4 4})] (prn (* b d)))
nil
"3\n8\n"
(for [[k v] '{a {foo 0, bar 22}, b {foo 3, bar 44}}] (assoc v :id k))
({:id a, bar 22, foo 0} {:id b, bar 44, foo 3})
(map #(or (and (not (coll? %)) %) (not-empty %)) [{} () {:a 0} [1] '(a b c) 'a "hello"])
(nil nil {:a 0} [1] (a b c) a "hello")
(reductions (fn [[total prev] n] [(str prev total n) n]) ["" ""] '[a b c d e f g])
(["" ""] ["a" a] ["aab" b] ["baabc" c] ["cbaabcd" d] ["dcbaabcde" e] ["edcbaabcdef" f] ["fedcbaabcdefg" g])
(let [name 'n parent '[a b c] fields '[d e f]] `(defrecord ~name ~(into parent fields)))
(clojure.core/defrecord n [a b c d e f])
(into {} (map (fn [[k i]] (vector k (nth (object-array '[a b c]) i))) (partition 2 [:foo 0 :bar 2])))
{:bar c, :foo a}
(let [a (delay (do (println "forced a") (+ 1 1))) b (delay (do (println "forced b") (+ @a 22)))] @a)
2
"forced a\n"
(reductions (fn [[total prev] n] [(str total n prev) n]) ["" ""] '[a b c d e f g])
(["" ""] ["a" a] ["aba" b] ["abacb" c] ["abacbdc" d] ["abacbdced" e] ["abacbdcedfe" f] ["abacbdcedfegf" g])
(defn foo [#^"[[J" x] (loop [a (long 0)] (recur (aget (let [#^"[J" y (aget x 1)] y) 1))))
#'user/foo
(map (fn [[k v]] (assoc v :id k)) '{a {foo 0, bar 22}, b {foo 3, bar 44}})
({:id a, bar 22, foo 0} {:id b, bar 44, foo 3})
(println "Is there a way in Clojure to atomically say: [if file XYZ does not exist; create file XYZ]")
nil
"Is there a way in Clojure to atomically say: [if file XYZ does not exist; create file XYZ]\n"
(intern *ns* '#^{:macro true} _defmacro (fn [n & a] `(intern *ns* '~(with-meta n {:macro true}) (fn ~@a))))
#'user/_defmacro
(reduce (fn [m [k v]] (update m k (fnil conj []) v)) {} (partition 2 '(:k1 a :k1 b :k2 c)))
{:k1 [a b], :k2 [c]}