(defn filter-first [pred s] (let [[a b] (split-with pred s)] (concat a (next b))))
#'user/filter-first
(let [{:keys [a b c]} {:a 1, :b 2, :c nil}] [a b c])
[1 2 nil]
(let [v [1 2 3]] (= (take (count v) (iterate inc (first v))) v))
true(defmacro hello [[msgs-name] & body] `(fn [msgs#] (println msgs#) (let [~msgs-name msgs#] ~@body)))
#'user/hello
(let [foo (fn f [x] (if (zero? x) x (f (dec x))))] (foo 10))
0(defmacro make-let [a b & cs] `(let [~@(mapcat vector a b)] ~@cs))
#'user/make-let
(defmacro defn-let [name args lettings & body] `(defn ~name ~args (let ~lettings ~@body)))
#'user/defn-let
(let [args [:foo "/foo" :bar "/bar"]] `(do ~(map str (partition 2 args))))
(do ("clojure.lang.LazySeq@5d847e33" "clojure.lang.LazySeq@5d2b26fe"))
(let [some-datum (list '+ (symbol "I worship His Shadow"))] (= some-datum (read-string (print-str some-datum))))
false(let [m {12 :a, 99 :b, 3 :c}] (dissoc m (apply max (keys m))))
{3 :c, 12 :a}
(let [[a b] [2 2]] (if (= 1 a) "a is 1" [a b]))
[2 2]
(let [a (hash-map Double/NaN 1)] (identical? (double (key (first a))) (double (key (first a)))))
false(let [x [1 2 3] s (seq x)] (identical? (rest s) (rest s)))
false(let [x [1 2 3] f (fn [y] (identical? x y))] (f x))
true(let [m {(rand) (rand)}] (apply = (repeatedly 100 #(zipmap (keys m) (vals m)))))
true(let [list '(a b c d)] (partition 2 1 (cons (last list) list)))
((d a) (a b) (b c) (c d))
(let [x (fn [a] (inc a)) y inc z inc] (x (y (z 1))))
4(let [add (fn [x y] (+ x y)) add-1 (partial add 1)] (add-1 2))
3(let [{:keys [x y], :as opts, :or {x 1}} {:y 2}] [x y opts])
[1 2 {:y 2}]
(let [i 3] ((juxt #(subs % 0 i) #(subs % i)) "abcdefg"))
["abc" "defg"]
(let [[w1 w2 w3 :as words] (clojure.string/split "hello how are you doing?" #"\s+")] words)
["hello" "how" "are" "you" "doing?"]
(let [a1 (String. "aa") a2 (String. "aa")] [(= a1 a2) (identical? a1 a2)])
[true false]
(binding [*print-meta* true] (prn (macroexpand '(let [foo ^{f ?, w t} []] foo))))
nil"^{:line 1, :column 49} (let [foo ^{w t, f ?} []] foo)\n"(macroexpand-1 '(let [{:keys [k1 k2], :or {k1 "foo", k2 "bar"}} m] [k1 k2]))
(let [{:keys [k1 k2], :or {k1 "foo", k2 "bar"}} m] [k1 k2])
(defmacro mac [exp] `(let [f (fn [n] (max 1 (- n external)))] ~exp))
#'user/mac
(let [[f m l :as parts] (clojure.string/split "first last" #"\s+")] (= m (second parts)))
true(let [form-a `(defn g []) form-b `(defn g? [])] (defmacro bar [] (do form-a form-b)))
#'user/bar
(let [a '(1 2 3) b (conj a 2)] (identical? a (rest b)))
true(let [m {"test" 1, "egr" 2, "wer`1" 3}] (print m) (print (into (sorted-map) m)))
nil"{test 1, egr 2, wer`1 3}{egr 2, test 1, wer`1 3}"(let [m {:127.0.0.1 5} ip :127.0.0.1] (assoc m ip {:occurences (ip m), :country "DK"}))
{:127.0.0.1 {:country "DK", :occurences 5}}
(let [{:keys [a b & c]} {:a 1, :b 2}] [a b & c])
[1 2 nil nil]
(let [latin1 (apply str (map char (range 32 255)))] (apply str (re-seq #"\w" latin1)))
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"(let [fns (for [i (range 3)] (fn [j] (+ i j)))] ((second fns) 3))
4(let [teams (range 1 9)] (map list (take 4 teams) (reverse (drop 4 teams))))
((1 8) (2 7) (3 6) (4 5))
(let [[[k0 v0] [k1 v1]] [[:a 1] [:b 2]]] (print k0 v0 k1 v1))
nil":a 1 :b 2"(let [f (fn [name] `(defn ~(symbol name) ...))] (f (str "bar" "foo")))
(clojure.core/defn barfoo user/...)
(let [r {:params {:username "u", :password "p"}} {{:keys [username password]} :params} r] [username password])
["u" "p"]
(let [a ['a 'b] b [1 2 3]] (cons (first b) (interleave a b)))
(1 a 1 b 2)
(defmacro fnn [f n] (let [syms (repeatedly n gensym)] `(fn [~@syms] (~f ~@syms))))
#'user/fnn
(let [f (fn [{:keys [a]}] a)] (#(f (merge {:a 1} %)) {:a 2}))
2(let [m {:fn (fn [x] (+ x x)), :arg 5}] ((:fn m) (:arg m)))
10(let [{:keys [a b c]} {:a 1, :b 2, :c 3}] [a b c])
[1 2 3]
(let [lst (range 10) [a b] (take-last 2 lst)] {:a a, :b b})
{:a 8, :b 9}
(let [n 2 double (fn double [x] (* n x))] (map double (range 5)))
(0 2 4 6 8)
(let [[a b] (split-with (partial not= 5) (range 0 50))] (concat a (rest b)))
(0 1 2 3 4 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49)
(defmacro moretimes [times body] `(let [*# #(apply * (conj %& ~times))] ~body))
#'user/moretimes
(let [{:keys [a b c :as all]} {:a 0, :b 1, :c 2}] all)
nil(let [[foo bar baz] (map #(% %2) [identity inc identity] [1 2 3])])
nil(let [[a b] (split-with (partial not= 3) (range 0 5))] (concat a (rest b)))
(0 1 2 4)
(let [a (atom {:a {:b 1}})] (swap! a update-in [:a :b] + 2) @a)
{:a {:b 3}}

