(let [a 'foo b `~(vary-meta a assoc :example true)] [b (meta b)])
[foo {:example true}]
(let [yield (fn [seq] (let [a (atom (cons nil seq))] (fn [] (first (swap! a next))))) test (yield (cycle [:conn1 :conn2 :conn3 :conn4]))] (for [_ (range 10)] (test)))
(:conn1 :conn2 :conn3 :conn4 :conn1 :conn2 :conn3 :conn4 :conn1 :conn2)
(do (def h2 {"a" 1, "b" 2}) (let [{:keys [a b]} h2] b))
nil(let [some-datum (list (symbol "I worship His Shadow"))] (= some-datum (read-string (print-str some-datum))))
false(let [{a :a, :as m} (list 1 2 3 4)] (println a m))
nil"nil {1 2, 3 4}\n"(let [l [1 2 3 2]] (apply max-key l (range 0 (count l))))
2(let [x true] `(1 2 3 ~(if x 4 5) 5))
(1 2 3 4 5)
(let [m (into {} (sorted-map :a 1 :b 2 :c 3))] [(class m) m])
[clojure.lang.PersistentArrayMap {:a 1, :b 2, :c 3}]
(let [foo :as {:keys [a b]} {:a 1, :b 2}] [a b foo])
[1 2 :as]
(defmacro foo [a] (let [bar (+ a 2)] `(fn [] (* ~bar 3))))
#'user/foo
(let [*modulus* 3] (take 3 (iterate #(-> % (inc) (mod *modulus*)) 1)))
(1 2 0)
(let [x 1] `(xxx (yyy (bbb (zzz ~x) ''~x) ~x '~x '~x)))
(user/xxx (user/yyy (user/bbb (user/zzz 1) (quote (quote 1))) 1 (quote 1) (quote 1)))
(let [a (atom (map #(print %) (range 35)))] (swap! a rest) nil)
nil"012345678910111213141516171819202122232425262728293031"(let [s (sorted-set-by (comp - compare) 1 3 4)] (into (empty s) s))
#{1 3 4}
(let [x [1 2] [a b] x] {:x x, :a a, :b b})
{:a 1, :b 2, :x [1 2]}
(let [[y & z] '(1 2 3 4 5 6 7)] z)
(2 3 4 5 6 7)
(let [x (reduce concat (map (constantly (vector 1 2 3)) (range 0 7393)))])
nil(let [coll (take 10 (iterate inc 1))] (/ (apply + coll) (count coll)))
11/2(defmacro foo [[arg] & body] `(let [~arg (list 1 2 3)] ~@body))
#'user/foo
(defmacro macro-test [name] `(let [fn-name# (symbol (str "prefix-" ~name))] (defn fn-name# [] 42)))
#'user/macro-test
(let [[a b] [:key "val"]] (str "key: " a " val: " b))
"key: :key val: val"(let [[hd & tl] (map #(doto % prn) (iterate inc 1))] hd)
1"1\n2\n"(let [fib-subseq [0 1 1 2 3 5]] (map + fib-subseq (rest fib-subseq)))
(1 2 3 5 8)
(let [s {:a 1, :b 2}] (and (contains? s :a) (contains? s :b)))
true(let [m {:b 4, :c 3, :e 7}] (key (apply min-key val m)))
:c(let [a 1 b #(+ a %) a 2] (b a))
3(let [{:syms [a b]} {'a 1, 'b 3, 'c 3}] (+ a b))
4(let [wanted [:a :b]] (merge (zipmap wanted (repeat nil)) (select-keys {:a 0} wanted)))
{:a 0, :b nil}
(let [test (fn [x] (when true x))] (list 'a 'b 'c (test 'x)))
(a b c x)
(defmacro dbg [x] `(let [x# ~x] (println "dbg:" '~x "=" x#) x#))
#'user/dbg
(let [x (for [x (range 10)] (do (println "Evaling" x) [x]))] (first x))
[0]
"Evaling 0\nEvaling 1\nEvaling 2\nEvaling 3\nEvaling 4\nEvaling 5\nEvaling 6\nEvaling 7\nEvaling 8\nEvaling 9\n"(do (defn tst [] (let [f (transient {})] (assoc! f :2 1) (persistent! f))) (tst))
{:2 1}
(let [lseq (map prn (range 3))] (if (seq lseq) (prn 'a) (prn 'b)))
nil"0\n1\n2\na\n"(let [s "[bla bla"] (try (read-string s) (catch Exception _ (identity s))))
"[bla bla"(let [a (object-array 5) v (vec a)] (aset a 0 :hi) v)
[:hi nil nil nil nil]
(defmacro dbg [x] `(let [x# ~x] (println "dbg:" '~x "=" x#) x#))
#'user/dbg
(let [syms (map symbol (seq (.split "a,b,c,d" ",")))] (printf "syms: %s\n" (seq syms)))
nil"syms: (a b c d)\n"(let [s "1234567890"] (map (partial apply str) (split-at (/ (count s) 2) s)))
("12345" "67890")
(defn true-times [n] (let [state (atom 0)] (fn [] (<= (swap! state inc) n))))
#'user/true-times
(let [coll [1 2 3 5 6 7]] (mapv - (rest coll) coll))
[1 1 2 1 1]
(let [{:keys [a b]} {:a 1, :b 2}] (format "a=%d, b=%d" a b))
"a=1, b=2"(let [f (fn [{a :name, b :age}] (str a b))] (f {:age 9}))
"9"(let [data [:a :b :c]] (for [e data] [e (remove #{e} data)]))
([:a (:b :c)] [:b (:a :c)] [:c (:a :b)])
(let [{{:keys [first], :as person} :person} {:person {:first "john", :age 21}}] [first person])
["john" {:age 21, :first "john"}]
(let [{:keys [foo bar]} {:foo 1, :bar 2}] (println (str foo "\t" bar)))
nil"1\t2\n"(do (def a 1) (let [f (comp #'a)] (with-redefs [a (constantly 2)] f)))
#'user/a
(let [to-vector #(or (and (vector? %) %) [%])] [(to-vector 1) (to-vector [1])])
[[1] [1]]
(defn read-bytes [s n] (let [bs (byte-array n)] (.read s bs) (seq bs)))
#'user/read-bytes
(let [m {:foo 42, :bar 23}] (zipmap (keys m) (map inc (vals m))))
{:bar 24, :foo 43}
(let [{a :a, :as m} (list 1 2 :a 4)] (println a m))
nil"4 {1 2, :a 4}\n"

