(->> "this is a test" (#(clojure.string/split % #" ")) (map reverse) (map #(apply str %)) (clojure.string/join " "))
"siht si a tset"
(apply (fn [_ w _ wo] {:w w, :wo wo}) [true '((a b) (c)) false '((d) (e f))])
{:w ((a b) (c)), :wo ((d) (e f))}
(println "is for evaluation of code embedded inside of a message (when you can't begin the message with &)")
nil
"is for evaluation of code embedded inside of a message (when you can't begin the message with &)\n"
(condp #(%1 %2) 'a '#{x y} "x or y" '#{a b} "a or b" "none of these")
"a or b"
(->> "this is a test" (#(clojure.string/split % #" ")) (map (comp #(apply str %) reverse)) (clojure.string/join " "))
"siht si a tset"
(reductions (fn [[total prev] n] [(str total prev n) n]) ["" ""] '[a b c d e f g])
(["" ""] ["a" a] ["aab" b] ["aabbc" c] ["aabbccd" d] ["aabbccdde" e] ["aabbccddeef" f] ["aabbccddeeffg" g])
(let [a (delay (do (println "forced a") (+ 1 1))) b (delay (do (println "forced b") (+ @a 22)))] nil)
nil
(let [a (delay (do (println "forced a") (+ 1 1))) b (delay (do (println "forced b") (+ @a 22)))] @b)
24
"forced b\nforced a\n"
((fn [a & [b c :as d]] {:a a, :b b, :c c, :d d}) 0 1 2 3 4)
{:a 0, :b 1, :c 2, :d (1 2 3 4)}
(for [m ['{a b, c d} '{e f, g h}] [k v] m :when (= v 'd)] k)
(c)
(reduce (fn [c [k v]] (assoc c k v)) {} (map #(list %1 %2) '(a b c d e) (range)))
{a 0, b 1, c 2, d 3, e 4}
(let [m1 '{a 1, b 2, c 3} m2 '{b 2, d 4, c 3}] (filter m1 (keys m2)))
(b c)
(let [m {:foo 0, :bar 2} v '[a b c]] (into {} (map #(vector % (v (m %))) (keys m))))
{:bar c, :foo a}
(reductions (fn [sum nextpair] [(+ (first sum) (first nextpair)) (second nextpair)]) '[1 a] '[[2 b] [3 c] [4 d]])
([1 a] [3 b] [6 c] [10 d])
(reduce (fn [c [k v]] assoc c k v) {} (map #(list %1 %2) '(a b c d e) (range)))
4
(let [p '{a 100, b 200, c 50} ks (keys p) cvs (reductions + 0 (vals p))] cvs)
(0 100 300 350)
(defmacro daset [a vals] `(let [#^doubles b# ~a] ~@(for [[idx val] (partition 2 vals)] `(aset b# ~idx ~val))))
#'user/daset
(let [data '[{:type dog, :attrs a, :val 3} {:type dog, :attrs b, :val 5}]] (:val (keep (comp #{'b} :attrs) data)))
nil
(for [suit '[H S D C] rank (concat '[a] (range 1 10) '[j q k])] (str rank suit))
("aH" "1H" "2H" "3H" "4H" "5H" "6H" "7H" "8H" "9H" "jH" "qH" "kH" "aS" "1S" "2S" "3S" "4S" "5S" "6S" "7S" "8S" "9S" "jS" "qS" "kS" "aD" "1D" "2D" "3D" "4D" "5D" "6D" "7D" "8D" "9D" "jD" "qD" "kD" "aC" "1C" "2C" "3C" "4C" "5C" "6C" "7C" "8C" "9C" "jC" "qC" "kC")
(do (def a 'b) (def b 'c) (def c 'd) (def d 'e) (def e 'f) (def f 'g) (def g 'a))
#'user/g
(let [fib-seed (fn [a b] (fn fib ([n] (fib n a b)) ([n f1 f2] (if (= n 1) f1 (recur (dec n) f2 (+ f1 f2)))))) fib-1-1 (fib-seed 1 1) fib-10-10 (fib-seed 10 10)] [(/ (float (fib-1-1 10)) (fib-1-1 9)) (/ (float (fib-10-10 10)) (fib-10-10 9))])
[1.6176470588235294 1.6176470588235294]
(defrecord Foo [a b c d e f g h i j k l m n o p q r s t])
#'user/Foo
(doseq [x '({:user "a", :reps {:a 1, :b 2}})] (let [{a :user, rs :reps} x] (for [to (keys rs)] (print to))))
nil
(let [fib-seed (fn [a b] (fn fib ([n] (fib n a b)) ([n f1 f2] (if (= n 1) f1 (recur (dec n) f2 (+ f1 f2)))))) fib-1-1 (fib-seed 1 1) fib-10-10 (fib-seed 10 10)] [(/ (float (fib-1-1 20)) (fib-1-1 19)) (/ (float (fib-10-10 20)) (fib-10-10 19))])
[1.6180339631667064 1.6180339631667064]
(apply merge-with + (map (fn [w] {w 1}) (.split "Returns a map that consists of the rest of the maps conj-ed onto" "\\s+")))
{"Returns" 1, "a" 1, "conj-ed" 1, "consists" 1, "map" 1, "maps" 1, "of" 2, "onto" 1, "rest" 1, "that" 1, "the" 2}
(let [data '[{:type dog, :attrs a, :val 3} {:type dog, :attrs b, :val 5}]] (:val (first (filter (comp #{'b} :attrs) data))))
5
((fn [i j] (for [k (range (count i))] `(~(i k) ~(j k)))) '[a b c] '[x y z])
((a x) (b y) (c z))
(let [data '[{:type dog, :attrs a, :val 3} {:type dog, :attrs b, :val 5}]] (:val (first (keep (comp #{'b} :attrs) data))))
nil
(defn checker [coll] (if (and (seq coll) (rest coll)) "it has a head and tail in it" "it has one or fewer elements"))
#'user/checker
(defmacro nif "Numeric if. `expr` must evaluate to a number." [expr pos zero neg] `(cond (pos? ~expr) ~pos (zero? ~expr) ~zero :else ~neg))
#'user/nif
((fn perm [r p] (if (seq r) (mapcat #(perm (disj r %) (conj p %)) r) [p])) '#{a b c d e} [])
([a e c b d] [a e c d b] [a e b c d] [a e b d c] [a e d c b] [a e d b c] [a c e b d] [a c e d b] [a c b e d] [a c b d e] [a c d e b] [a c d b e] [a b e c d] [a b e d c] [a b c e d] [a b c d e] [a b d e c] [a b d c e] [a d e c b] [a d e b c] [a d c e b] [a d c b e] [a d b e c] [a d b c e] [e a c b d] [e a c d b] [e a b c d] [e a b d c] [e a d c b] [e a d b c] [e c a b d] [e c a d b] [e c b a d] [e ...
(hash "merry had a little lamb whose fleece was white as snow, and every where that mary went the lamb was sure to go")
-565463861
(for [msg ["good morning" "yesterday morning we fixed a bug" "good evening everyone" "the evening is boring"]] (re-find #"(?i)\bgood\b (morning|afternoon|evening|night|day)\b" msg))
(["good morning" "morning"] nil ["good evening" "evening"] nil)
(defn checker [coll] (if (and (seq coll) (seq (rest coll))) "it has a head and tail in it" "it has one or fewer elements"))
#'user/checker
(reductions (fn [sum nextpair] (prn 'schedule sum) [(+ (first sum) (first nextpair)) (second sum)]) '[1 a] '[[2 b] [3 c] [4 d]])
([1 a] [3 a] [6 a] [10 a])
"schedule [1 a]\nschedule [3 a]\nschedule [6 a]\n"
(defn f [rs] (partition 2 (rest (mapcat (fn [[a b] [c d]] (when (not= b c) [b c])) (cons nil rs) (concat rs [nil])))))
#'user/f
(munge "gtrak: that story is actually a bit dubious - it's typically presented with \"random\" rearrangements that are easier to read than most orderings")
"gtrak_COLON_ that story is actually a bit dubious _ it_SINGLEQUOTE_s typically presented with _DOUBLEQUOTE_random_DOUBLEQUOTE_ rearrangements that are easier to read than most orderings"
(defmacro runtime-new "Much like new, but the first argument can be anything that evaluates to a class" [class & args] `(clojure.lang.Reflector/invokeConstructor class (to-array args)))
#'user/runtime-new
(letfn [(myrange [n] (take n (iterate (fn [x] (print x " ") (inc x)) 0))) (mytest [a b & others])] (apply mytest (myrange 10)))
nil
"0 1 2 "
(for [l0 '[a b c] l1 '[1 2 3] :while (< l1 3) l2 '[d e f]] (str l0 l1 l2))
("a1d" "a1e" "a1f" "a2d" "a2e" "a2f" "b1d" "b1e" "b1f" "b2d" "b2e" "b2f" "c1d" "c1e" "c1f" "c2d" "c2e" "c2f")
(defn fmap [f m] "Given a map `m`, apply `f` to each value, maintaining keys" (reduce-kv (fn [acc k v] (assoc acc k (f v))) m m))
#'user/fmap
((fn cart [coll] (lazy-seq (if (empty? coll) '(()) (for [more (cart (rest coll)) x (first coll)] (cons x more))))) '((a b) (c) (d e) (f)))
((a c d f) (b c d f) (a c e f) (b c e f))
(clojure.core/loop [G__2053 (clojure.core/seq (range 10))] (clojure.core/when G__2053 (clojure.core/let [a (clojure.core/first G__2053)] (clojure.core/loop [G__2054 (clojure.core/seq (range 10))] (clojure.core/when G__2054 (clojure.core/let [b (clojure.core/first G__2054)] (do) (recur (clojure.core/next G__2054))))) (recur (clojure.core/next G__2053)))))
nil
((fn perm [r m p] (if (> m 0) (mapcat #(perm (disj r %) (dec m) (conj p %)) r) [p])) '#{a b c d e} 5 [])
([a e c b d] [a e c d b] [a e b c d] [a e b d c] [a e d c b] [a e d b c] [a c e b d] [a c e d b] [a c b e d] [a c b d e] [a c d e b] [a c d b e] [a b e c d] [a b e d c] [a b c e d] [a b c d e] [a b d e c] [a b d c e] [a d e c b] [a d e b c] [a d c e b] [a d c b e] [a d b e c] [a d b c e] [e a c b d] [e a c d b] [e a b c d] [e a b d c] [e a d c b] [e a d b c] [e c a b d] [e c a d b] [e c b a d] [e ...
(filter #(re-matches #"[sb]a[gd]" %) (let [abc (map char (range (int \a) (inc (int \z))))] (for [x abc y abc z abc] (str x y z))))
("bad" "bag" "sad" "sag")
(apply str (reverse (interpose " " (.split "fun for aside language based stack a in point the see don't I but, Forth resembles it and briefly Factor studied I" " "))))
"I studied Factor briefly and it resembles Forth but, I don't see the point in a stack based language aside for fun"
(#(into {} (map (fn [where] [where (get-in % where)]) (mapcat (fn [k] (map (fn [k'] [k k']) (keys (get % k)))) (keys %)))) '{m {1 [a b c], 3 nil}})
{[m 1] [a b c], [m 3] nil}
(let [m "merry had a little lamb whose fleece was white as snow, and every where that mary went the lamb was sure to go"] [(hash m) (sort [(hash m) (hash "a")]) (sort [m "a"])])
[-565463861 (-565463861 1455541201) ("a" "merry had a little lamb whose fleece was white as snow, and every where that mary went the lamb was sure to go")]
((fn [a b c d e f g h i j k l m n o p q r s t & u] :foo) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21)
:foo
((fn foo [a b c d e f g h i j k l m n o p q r s t & z] z) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22)
(21 22)