(let [+ (fn [& args] (- (apply - 0 args)))] (+ 10 20))
30(let [[h & t] [1 2 3 4 5]] {:head h, :tail t})
{:head 1, :tail (2 3 4 5)}
(let [ba (byte-array (map byte [1 2 3 4]))] [ba (take 5 ba)])
[#object ["[B" 0x2e04c610 "[B@2e04c610"] (1 2 3 4)]
(let [m {:a 1, :b 2}] (zipmap (keys m) (map inc (vals m))))
{:a 2, :b 3}
(let [x (apply concat (repeatedly #(lazy-seq (do (print "X") [1 2 3]))))])
nil(let [coll (range 10)] (concat (partition 2 1 coll) [(last coll) (first coll)]))
((0 1) (1 2) (2 3) (3 4) (4 5) (5 6) (6 7) (7 8) (8 9) 9 0)
(let [m [1 4 2 7 8 5]] (apply (juxt min max) m))
[1 8]
(let [x (transient (hash-map))] (dotimes [n 100] (assoc! x n n)) (persistent! x))
{0 0, 1 1, 2 2, 3 3, 4 4, 5 5, 6 6, 7 7}
(binding [*print-meta* true] (prn '(let [z 0] (meta '#^{:a :b} z))))
nil"^{:line 1, :column 36} (let [z 0] ^{:line 1, :column 47} (meta ^{:line 1, :column 53} (quote ^{:a :b} z)))\n"(let [some-datum (list (symbol "Minä palvon Hänen Varjoansa"))] (= some-datum (read-string (print-str some-datum))))
false(let [f (fn [coll] (into coll [[1 2] [3 4]]))] (f {5 6}))
{1 2, 3 4, 5 6}
(let [t (transient {})] (dotimes [n 40] (assoc! t n n)) (keys (persistent! t)))
(0 1 2 3 4 5 6 7)
(let [a (atom 1)] (swap! a (fn [val i] (+ val i)) 1))
2(let [m {:x 1, :y 2}] (zipmap (keys m) (map inc (vals m))))
{:x 2, :y 3}
(let [x (for [i (range 0 2)] (do (println i) i))] (doall x))
(0 1)
"0\n1\n"(let [x (concat (do (println 1) [1]) (do (println 2) [2]))] (first x))
1"1\n2\n"(let [ton #(apply + (map int %))] (list (ton "scheme") (ton "clojure")))
(629 756)
(let [{:keys [c d], :or {:c 0, :d 0}} {:d 5}] [c d])
[nil 5]
(let [trailing-nl (. "foo" endsWith "o") x (if trailing-nl "" "no")] (println x))
nil"\n"(let [init [1 2 3] v2 (conj init 4)] {:states [init v2]})
{:states [[1 2 3] [1 2 3 4]]}
(let [a (atom 0)] (while (> 10 @a) (swap! a inc)) (println @a))
nil"10\n"(let [sr (java.io.StringReader. "hello, world!")] (apply str (repeatedly 5 #(char (.read sr)))))
"hello"(let [{{first :first, :as person} :person} {:person {:first "john", :age 21}}] [first person])
["john" {:age 21, :first "john"}]
(let [x (reduce concat (map (constantly (vector 1 2 3)) (range 0 1900)))])
nil(let [{:keys [x y z]} '(:x 7 :z 10)] [x y z])
[7 nil 10]
(let [[foo1 & fooN] [1 2 3]] (if (empty? fooN) foo1 (first fooN)))
2(let [a {:b 1} m {:a a}] (identical? m (assoc m :a a)))
true(let [a 5 a (* 2 a) a (* 2 a)] a)
20(let [{:keys [foo bar], :or {bar 0}} {:foo 20}] {:foo foo, :bar bar})
{:bar 0, :foo 20}
(let [{:keys [parents]} {:first "John", :last "Doe", :parents {:mother "Alicia", :father "George"}}] parents)
{:father "George", :mother "Alicia"}
(let [x 1] (loop [x x] (if (zero? x) :done (recur (dec x)))))
:done(defmacro safe-math [expr] (let [e (gensym)] `(try ~expr (catch java.lang.ArithmeticException ~e "careful!"))))
#'user/safe-math
(let [_ (map + [1 [2] 3])] "this works because of lazy eval")
"this works because of lazy eval"(let [{:keys [fname lname], :as person} {:fname "John", :lname "Smith"}] [fname lname person])
["John" "Smith" {:fname "John", :lname "Smith"}]
(let [a nil] (-> 5 ((fn [x] (if a (+ x a) x)))))
5(let [f identity x '(1 2 3)] (into (empty x) (f x)))
(3 2 1)
(let [ "even number of forms, eh?" "let's make it even" "or not"] )
"let's make it even"(let [v [[1 2] [3 4]]] (update-in v [(dec (count v))] conj 5))
[[1 2] [3 4 5]]
(defmacro x [] (let [name 'y] `(defn ~(with-meta name {:foo :bar}) [] :y)))
#'user/x
(let [foo "bar" baz "quux"] (into {} (map (fn [k] [`'~k k]) [foo baz])))
{(quote "bar") "bar", (quote "quux") "quux"}
(let [[x y & m] (range 9)] {:x x, :y y, :m m})
{:m (2 3 4 5 6 7 8), :x 0, :y 1}
(let [abs (fn [x] (max x (- x)))] (map abs [-2 7 -3]))
(2 7 3)
(let [fns [unchecked-divide-int mod quot rem /]] (map #(% -20 6) fns))
(-3 4 -3 -2 -10/3)
(let [a (atom {})] (swap! a assoc :a 0) (swap! a assoc :b 1))
{:a 0, :b 1}
(let [{:keys [a], :as m} {:a 42, :b 11}] [a (dissoc m :b)])
[42 {:a 42}]
(let [{foo :foo, :or {foo (prn "this should not print")}} {:foo "bar"}] foo)
"bar""\"this should not print\"\n"(let [{:keys [a b], :as m} {:a 1, :b 2}] [a b m])
[1 2 {:a 1, :b 2}]
(let [i (int 10) L (long 10) m {i i}] (get m L))
10(let [s [{:id 1} {:id 2}]] (zipmap (map #(:id %) s) s))
{1 {:id 1}, 2 {:id 2}}
(let [{:keys [ns name arglists macro]} {:ns 'foo, :name 'bar}] [ns name arglists])
[foo bar nil]

