(let [{:keys [a b]} {:a 21, :b 2}] (* a b))
42(let [v [1 2 3]] (into {} [[(seq v) 1] [v 2]]))
{(1 2 3) 2}
(defn make-adder [x] (let [y x] (fn [z] (+ y z))))
#'user/make-adder
(defmacro let-threaded [val varname & body] `(let [~varname ~val] ~@body))
#'user/let-threaded
(let [[a b c d e f g h] (range)] h)
7(let [a 0xf000] (if (< a 0x8000) a (- a 0x10000)))
-4096(defn foo [s] (let [re #"\d+"] (when (re-seq re s) true)))
#'user/foo
(let [coll [:a :b :c]] (partition 2 1 (cons :prefix coll)))
((:prefix :a) (:a :b) (:b :c))
(let [s #{:a :b :c :d}] [(first s) (rest s)])
[:c (:b :d :a)]
(defn func ([] (func 1)) ([p] (let [p (- p 1)]) p))
#'user/func
(let [a {:a :b, :c :d}] (pr-str (map reverse (into [] a))))
"((:b :a) (:d :c))"(let [afn (fn [i] inc i)] (map afn [1 2 3]))
(1 2 3)
(let [a 5 b (* 2 a) a 2] a)
2(let [a 0 b 1] (+ a a a b b))
2(let [a 2 _ (println a) b 3] (+ a b))
5"2\n"(let [middle [4 5 6]] `[10 11 ~@middle 12 13])
[10 11 4 5 6 12 13]
(let [coll [200 200]] (identical? (nth coll 0) (nth coll 1)))
false(let [{t true, f false} {true 'xs, false 'ys}] [t f])
[xs ys]
(let [foo (fn [x y] (+ x y))] (foo 4 5))
9(let [x 10] (filter (fn [item] (< item 10)) (range 30)))
(0 1 2 3 4 5 6 7 8 9)
(let [a {:foo [10 20 30]}] (-> a :foo (nth 1)))
20(let [x [1 2 3] y (into x [2])] [x y])
[[1 2 3] [1 2 3 2]]
(let [exp '(mainreq ctx)] `(with-open [~'ctx (zmq/context 1)] ~exp))
(clojure.core/with-open [ctx (zmq/context 1)] (mainreq ctx))
(let [m {:a "m", :b "m"}] (zipmap (vals m) (keys m)))
{"m" :b}
(let [intrange (range 0 10000)] (doseq [anint intrange] (+ anint anint)))
nil(let [things [[1 2] [3 4]]] (for [[x y] things] y))
(2 4)
(let [start [1 2 3]] (identical? start (pop (conj start 4))))
false(let [x [1 2 3]] [(concat x [4]) (concat x [5])])
[(1 2 3 4) (1 2 3 5)]
(let [[function & args] (list '/ 1 3)] (apply function args))
3(let [{foo 1, bar 3} [:a :b :c :d]] [foo bar])
[:b :d]
(let [key :foo] ((fn [& {:keys [foo]}] (prn foo)) key 1))
nil"1\n"(let [name 'test] `(defn ~(symbol (str name "?")) [] (...)))
(clojure.core/defn test? [] (user/...))
(let [[[a b] c] [[1 2] 3]] (vector a b c))
[1 2 3]
(let [[f s] (clojure.string/split "split me" #" " 1)] [f s])
["split me" nil]
(let [a 0 _ (println a) b 1] (* 3 b))
3"0\n"(let [[f & vs] '(/ 16 8)] `(~f vs))
(/ user/vs)
(let [k 10] (println k) (+ k 1) (+ k 2))
12"10\n"(defmacro mac [] `(let [x# '(1 2 3)] (first x#)))
#'user/mac
(let [[f l] (.split "hello.txt" "\\.")] (str f "-timestamp" "." l))
"hello-timestamp.txt"(let [[& {:keys [foo bar]}] [:foo 'a :bar 'b]] [foo bar])
[a b]
(defmacro with-letters [expr] `(let [~@(mapcat (fn [i] (let [sym (-> i char str symbol)] [sym (list 'quote sym)])) (range 97 123))] ~expr))
#'user/with-letters
(let [m (transient (apply hash-map (range 20)))] (dotimes [n 10000] (assoc! m n (inc n))) (let [m' (persistent! m)] [(count m') (get m' 4567)]))
[10000 4568]
(let [params '(1 2 3 4 5)] (apply + params))
15(let [{aa :a, bb :b} {:a 1, :b 2}] [aa bb])
[1 2]
(let [c [{:name "foo"} {:name "bar"}]] (zipmap (map :name c) c))
{"bar" {:name "bar"}, "foo" {:name "foo"}}
(let [x [1 2 3 4]] (zipmap x (map inc x)))
{1 2, 2 3, 3 4, 4 5}
(let [{a 0, b 3} [4 5 6 7]] [a b])
[4 7]
((fn [x] (when x (let [y (not x)] (recur y)))) true)
nil(let [{a :a, b :b} [:a 1 :b 2]] [a b])
[nil nil]
(defmacro mylet [sym expr & body] `(let [~sym ~expr] ~@body))
#'user/mylet

