(println "cran1988: Use a comma at the beginning of the line to run some Clojure.")
nil
"cran1988: Use a comma at the beginning of the line to run some Clojure.\n"
(map hash-map [1 2 3] [4 5 6] [7 8 9] '[a b c])
({1 4, 7 a} {2 5, 8 b} {3 6, 9 c})
(apply concat (for [x [1 2 3]] (for [y '(a b c)] [x y])))
([1 a] [1 b] [1 c] [2 a] [2 b] [2 c] [3 a] [3 b] [3 c])
(map #(map list %) '(((1 2 3) (a b c) (z y x))))
((((1 2 3)) ((a b c)) ((z y x))))
(let [{:keys [a b c d]} {:a 0, :b 2, :c 4, :d 8}] d)
8
(map #(map list %) '((1 2 3) (a b c) (z y x)))
(((1) (2) (3)) ((a) (b) (c)) ((z) (y) (x)))
((fn [& args] (apply (fn [a & b] (apply list b)) args)) 1 2 3)
(2 3)
(let [{:keys [a b c], :or {c 0}, :as args} {:a 1, :b 2}] args)
{:a 1, :b 2}
(map (fn [x y] (println x y)) '[a b c] '[d e f])
(nil nil nil)
"a d\nb e\nc f\n"
(filter #(= true %) '(a b true c true d e f true))
(true true true)
(str "Notte you can call code with a comma-starting line: " (+ 1 2 3))
"Notte you can call code with a comma-starting line: 6"
(apply merge-with + (for [[k v] '((a 1) (b 1) (b 3))] {k v}))
{a 1, b 4}
(let [{:keys [a b & ss]} {:a 1, :b 2, :c 3, :d 4}] ss)
nil
(defn make-records [] (doseq [[rec-name arglist] '{A [b], C [d]}] (eval `(defrecord ~rec-name ~arglist))))
#'user/make-records
(reduce (fn [m v] (assoc m v (str v "_val"))) {} '(a b c d))
{a "a_val", b "b_val", c "c_val", d "d_val"}
(letfn [(parse-fraction [xs] (let [[m n] (reduce (fn [[a b] x] [(+ x (* a 10)) (* b 10)]) [0 0.1] xs)] (* 0.1 (/ m n))))] (parse-fraction [1 2 3 4]))
0.12340000000000001
(let [a (promise) b (promise)] (deliver a (fn [x] (if (< x 10) x (@b (/ x 2))))) (deliver b (fn [x] (if (> x 100) x (@a (* x 13/10))))) (@a 42))
599781/80000
(let [a (promise) b (promise)] (deliver a (fn [x] (if (< x 0) x (@b (/ x 2))))) (deliver b (fn [x] (if (> x 100) x (@a (- x 10))))) (@a 20))
-10
(map (fn [[_ _ c] [a b _]] [a b c]) [[1 2 100] [1 2 100] [1 2 100]] [[4 5 200] [4 6 100] [4 7 200]])
([4 5 100] [4 6 100] [4 7 100])
(let* [m {:a 1, :b 2, :d 4} map__126488 m map__126488 (if (clojure.core/seq? map__126488) (clojure.core/apply clojure.core/hash-map map__126488) map__126488) c (clojure.core/get map__126488 :c) b (clojure.core/get map__126488 :b) a (clojure.core/get map__126488 :a)] [a b c])
[1 2 nil]
(letfn [(foo [a b & therest] (chunked-seq? therest))] [(apply foo (range 1000)) (chunked-seq? (range 1000))])
[true true]
(defn -main "I don't do a whole lot ... yet" [& args] (println "Hello, World!"))
#'user/-main
(let [{:keys [a b c], :or {c 0}, :as args} {:a 1, :b 2}] c)
0
(#(* %) #_(if youre happy and you know it print a one) (*))
1
(defn myfn "this fn takes an int and a double" [i d] (+ i d))
#'user/myfn
(reduce #(assoc %1 %2 (inc (%1 %2 0))) {} '(a b b c c c))
{a 1, b 2, c 3}
(#(do (flatten (-> (last %) (list (reverse (rest (reverse %))))))) '(a b c 2))
(2 a b c)
(get-in '[{:type dog, :attrs a, :val 3} {:type dog, :attrs b, :val 5}] [1 :val])
5
(apply merge-with into {} (for [x '(a b c) y '(1 2 3)] {x [y]}))
{a [1 2 3], b [1 2 3], c [1 2 3]}
(binding [*print-meta* true] (pr-str (macroexpand '(let [{:keys [^String a ^Integer b]} c ^Float d 1.0]))))
"^{:line 1, :column 52} (let [{:keys [^String a ^Integer b]} c ^Float d 1.0])"
(sort-by count '('(a b c) '(xx) '(aa bb cc dd) '(oo)))
((quote (a b c)) (quote (xx)) (quote (aa bb cc dd)) (quote (oo)))
(do (defrecord Example [a b]) [(Example. 1 2) (->Example 1 2) (map->Example {:a 1, :b 2})])
[#user.Example {:a 1, :b 2} #user.Example {:a 1, :b 2} #user.Example {:a 1, :b 2}]
(let [items '[a b c d e f g h]] (map list items (rest items)))
((a b) (b c) (c d) (d e) (e f) (f g) (g h))
(#(do (flatten (->> (last %) (list (reverse (rest (reverse %))))))) '(a b c 2))
(a b c 2)
(defn get-array-dims [a] (map count (take-while identity (iterate first (make-array Object 1 2 3 4 5)))))
#'user/get-array-dims
(apply merge-with + {} (for [x '(a b c) y '(1 2 3)] {x y}))
{a 6, b 6, c 6}
(for [[k v] (group-by second '([a :a] [b :a] [c :b]))] [k (map first v)])
([:a (a b)] [:b (c)])
(let [x '(a b c d e f g)] [(take 2 x) (drop 2 x)])
[(a b) (c d e f g)]
(do (defrecord Foo [a]) [(type (dissoc (map->Foo {:a 1}) :a)) (type (dissoc (map->Foo {'a 1}) 'a))])
[user/Foo user/Foo]
(apply str "I'd like " (map (fn [fruit] (str " a " fruit)) ["apple" "pear" "banana"]))
"I'd like a apple a pear a banana"
(let [not-number #_(+ 1 2 (* 3 5)) "is a string" #_(dumb-binding-unwanted nil)] not-number)
"is a string"
(reduce (fn [x y] (let [a (get x 1) b (get y 1)] (if (pos? (compare a b)) x y))) [["Coke" "16" ""] ["Coke" "35" "3"] ["Coke" "2" "3"] ["Pepsi" "" ""] ["Coke" "" "36"]])
["Coke" "35" "3"]
(reduce (fn [x y] (let [a (get x 1) b (get y 1)] (if (neg? (compare a b)) x y))) [["Coke" "16" ""] ["Coke" "35" "3"] ["Coke" "2" "3"] ["Pepsi" "" ""] ["Coke" "" "36"]])
["Coke" "" "36"]
((fn [a b & c] (let [opts (apply hash-map c)] (:key opts))) :foo :bar :key "val")
"val"
(apply str "I'd like " (map (fn [fruit] str " a " fruit) ["apple" "pear" "banana"]))
"I'd like applepearbanana"
(reduce (fn [r v] (cons (str v "=") (cons v r))) '() '(a b c))
("c=" c "b=" b "a=" a)
(let [coll (range 1 25) target 12 cnt (count coll)] (->> (for [a (range 0 cnt) b (range 1 cnt)] [(nth coll a) (nth coll b)]) (filter (fn [[x y]] (= target (+ x y))))))
([1 11] [2 10] [3 9] [4 8] [5 7] [6 6] [7 5] [8 4] [9 3] [10 2])
(first (filter (comp not nil?) (map 'e ['{a b, c d} '{e f, g h}])))
f
(letfn [(if [c t f] (println "Fooled you"))] (if true (println "If's not a function") (println "umm...")))
nil
"If's not a function\n"
(for [x '[a b c] y [1 2 3 4] :while (< y 3)] [x y])
([a 1] [a 2] [b 1] [b 2] [c 1] [c 2])