(let [a [[1 12] [2 23] [5 65]] m (into (sorted-map) a)] (map m (-> a last first inc range) (repeat 0)))
(0 12 23 0 0 65)
(let [a {:a 1, :b 0, :c 1}] (let [m (reduce max (vals a))] (for [[k v] a :when (= v m)] k)))
(:a :c)
(map (fn [[k v]] (list* (name k) v)) (apply merge-with (fn [a b] (conj (if (list? a) a (list a)) b)) [{:text "asdad", :value "123"} {:text "asdad", :value "123"} {:text "asdad", :value "123"}]))
(("text" "asdad" "asdad" "asdad") ("value" "123" "123" "123"))
(for [c (range 1 11) b (range 1 c) a (range 1 b) :when (and (= (+ (* a a) (* b b)) (* c c)) (= (+ a b c) 24))] [a b c])
([6 8 10])
(for [c (range 100) :let [c2 (* c c)] b (range c) :let [b2 (* b b)] a (range b) :when (= c2 (+ b2 (* a a)))] [a b c])
([3 4 5] [6 8 10] [5 12 13] [9 12 15] [8 15 17] [12 16 20] [15 20 25] [7 24 25] [10 24 26] [20 21 29] [18 24 30] [16 30 34] [21 28 35] [12 35 37] [15 36 39] [24 32 40] [9 40 41] [27 36 45] [30 40 50] [14 48 50] [24 45 51] [20 48 52] [28 45 53] [33 44 55] [40 42 58] [36 48 60] [11 60 61] [39 52 65] [33 56 65] [25 60 65] [16 63 65] [32 60 68] [42 56 70] [48 55 73] [24 70 74] [45 60 75] [21 72 75] [3...
(defn make-rangemapper [a b a' b'] (let [scale (/ (- b' a') (- b a))] (fn [x] (+ a' (* (- x a) scale)))))
#'user/make-rangemapper
(let [a (into {} [[0 12] [1 23] [3 65]]) b (apply max (map first a))] (map #(get a % 0) (range (inc b))))
(12 23 0 65)
(map (fn [[k v]] (apply vector (name k) v)) (apply merge-with (fn [a b] (conj (if (vector? a) a [a]) b)) [{:text "asdad", :value "123"} {:text "asdad", :value "123"} {:text "asdad", :value "123"}]))
(["text" "asdad" "asdad" "asdad"] ["value" "123" "123" "123"])
(-> '((E (C) (F I) F) (A A) H ((G) B) ((E G (I (I I A)) H I) (B) (A) C (D (H))) (F C C)) pr-str (clojure.string/replace " " ""))
"^{:line1,:column6}(^{:line1,:column7}(E^{:line1,:column10}(C)^{:line1,:column14}(FI)F)^{:line1,:column23}(AA)H^{:line1,:column31}(^{:line1,:column32}(G)B)^{:line1,:column39}(^{:line1,:column40}(EG^{:line1,:column45}(I^{:line1,:column48}(IIA))HI)^{:line1,:column62}(B)^{:line1,:column66}(A)C^{:line1,:column72}(D^{:line1,:column75}(H)))^{:line1,:column81}(FCC))"
(remove #(contains? '#{a b nil Double/NaN} %) '[a b c nil Double/NaN])
(c)
(letfn [(f [a b c] {:a a, :b b, :c c})] (f 1 2 3))
{:a 1, :b 2, :c 3}
(map (fn [a b c] (a b c)) '(list list) [1 1] [2 2])
(2 2)
((fn [& {:keys [a b c]}] [a b c]) :a 1 :b 2 :c 3)
[1 2 3]
(defn foo [k v & {:keys [a b], :as m, :or {k v}}] [a b])
#'user/foo
(let [make-adder (fn [a] (fn [x] (+ a x))) adder-5 (make-adder 5)] (adder-5 10))
15
(defn -main "I don't do a whole lot...yet." [& args] println "I'm a little teapot!")
#'user/-main
(let [{:keys [a b c], :as all, :or {b 2, c 3}} {}] [a b c])
[nil 2 3]
(map (fn [[a b]] (+ a b)) (partition 2 1 [1 2 3 4 5]))
(3 5 7 9)
(for [a [:a :b :c :d :e] b [1 2 3 4 5]] [a b])
([:a 1] [:a 2] [:a 3] [:a 4] [:a 5] [:b 1] [:b 2] [:b 3] [:b 4] [:b 5] [:c 1] [:c 2] [:c 3] [:c 4] [:c 5] [:d 1] [:d 2] [:d 3] [:d 4] [:d 5] [:e 1] [:e 2] [:e 3] [:e 4] [:e 5])
((fn [a b & {c :name}] [a b c]) 1 2 :name "steve" :age "paul")
[1 2 "steve"]
(reduce (fn [a _] (pop a)) [1 2 3 4 5 6] (repeat 3 nil))
[1 2 3]
((fn [& {:keys [a b c]}] [a b c]) {:a 1, :b 2, :c 3})
[1 2 3]
(map (fn [[a b]] (+ a b)) (partition 2 [1 2 3 4 5 6]))
(3 7 11)
(every? (fn [[a b]] (== (inc a) b)) (partition 2 1 [4 5 5 7]))
false
(let [a (atom 0) foo (constantly (do (swap! a inc) :hi))] (foo) (foo) (foo) @a)
1
(reduce (fn [_ a] (println a) (reduced 9)) (seq (long-array [1 2 3 4 5])))
9
"2\n"
(reduce (fn [a [coords e]] (assoc-in a coords e)) [[] [] []] [[[0 0] "a"] [[0 1] "b"]])
[["a" "b"] [] []]
(let [f #(* % %) g (fn [f x] (let [a (f x)] (println x a) a))] (map #(g f %) (range 5)))
(0 1 4 9 16)
"0 0\n1 1\n2 4\n3 9\n4 16\n"
(seq (reduce (fn [m [a b]] (if (contains? m a) m (assoc m a b))) (sorted-map) [[2 4] [1 3] [1 2] [2 6]]))
([1 3] [2 4])
(let [a (make-array Double/TYPE 5 5) b (aclone a)] (aset b 2 0 -9.3) (println (aget b 2 0)) (println (aget a 2 0)))
nil
"-9.3\n-9.3\n"
(let [l [{:key "a", :val "a"} {:key "b", :val "b"} {:key "c", :val "c"}]] (for [a l b l :when (not= a b)] [a b]))
([{:key "a", :val "a"} {:key "b", :val "b"}] [{:key "a", :val "a"} {:key "c", :val "c"}] [{:key "b", :val "b"} {:key "a", :val "a"}] [{:key "b", :val "b"} {:key "c", :val "c"}] [{:key "c", :val "c"} {:key "a", :val "a"}] [{:key "c", :val "c"} {:key "b", :val "b"}])
(for [a [{:name :joe, :age 10} {:name :bob, :age 12}] b [{:name :joe, :age 10} {:name :bob, :age 13}] :when (and (= (:name a) (:name b)) (not= (:age a) (:age b)))] [a b])
([{:age 12, :name :bob} {:age 13, :name :bob}])
(letfn [(a [x] (if (< x 10) x (b (/ x 2)))) (b [x] (if (> x 100) x (a (* x 13/10))))] (a 42))
599781/80000
(let [a 23] (doseq [b (range 24)] (print (min (rem (+ 24 (- a b)) 24) (rem (+ 24 (- b a)) 24)) " ")))
nil
"1 2 3 4 5 6 7 8 9 10 11 12 11 10 9 8 7 6 5 4 3 2 1 0 "
(defn f [x y z & args] (apply (fn [& a] a) x y z args))
#'user/f
((fn [& {:keys [a b c]}] (str a "-" b "-" c)) :a "hello" :b "world")
"hello-world-"
(let [{:keys [a b c], :or {:a 0, :b 1}, :as point} {}] [[a b c] point])
[[nil nil nil] {}]
(let [a (atom 0)] (second (map (fn [_] (swap! a inc)) (filter identity (range 50)))) @a)
32
(reduce (fn [[a b] [c d]] [(+ a c) (+ b d)]) (repeat 10 [1 2]))
[10 20]
(map (fn [[a b]] (- b a)) (partition 2 1 [1 2 3 5 6 7]))
(1 1 2 1 1)
(letfn [(f [a b c] {:a a, :b b, :c c})] (apply f [1 2 3]))
{:a 1, :b 2, :c 3}
((fn [[a b & c :as d]] (println a b c d)) [:foo :bar :bat :baz])
nil
":foo :bar (:bat :baz) [:foo :bar :bat :baz]\n"
(let [[a b c & more] [:a :b :c :d :e :f]] [a b c more])
[:a :b :c (:d :e :f)]
((fn [& a] (let [{:keys [x y]} (apply hash-map a)] [x y])) :x 1 :y 2)
[1 2]
(for [[a b c] (partition 3 '(1 2 3 4 5))] (list c b a))
((3 2 1))
(defn foo [& args] (let [{:keys [a b c]} (apply hash-map args)] (list a b c)))
#'user/foo
(map (fn [[a b]] (- b a)) (partition 2 1 '(0 250 500 750 1000)))
(250 250 250 250)
(defn toggler-factory [f1 f2] (let [a (atom true)] (fn [] (if @a (f1) (f2)) (swap! a not))))
#'user/toggler-factory
((fn [a b & c] [a b c (class c)]) 1 2 :name "steve" :age "paul")
[1 2 (:name "steve" :age "paul") clojure.lang.ArraySeq]
(reduce (fn [a [k v]] (assoc a k (inc v))) {} {:a 1, :b 2, :c 3})
{:a 2, :b 3, :c 4}