(let [x¹ 4 x² 1 x³ 2] (* x³ (+ x² x¹)))
10(let [myvec [1 [2 3 4 [5]]]] (get-in myvec [1 3 0]))
5(let [m (map #(do (println "a") %) [1 2 3])] m)
(1 2 3)
"a\na\na\n"(do (let [ns (ns-name *ns*)] (in-ns 'foo) (def bar 42) (in-ns ns)))
nil(let [a (atom {:foo 0, :bar 0})] (swap! a update :foo inc))
{:bar 0, :foo 1}
(let [{even true, others false} (group-by even? (range -5 5))] [even others])
[[-4 -2 0 2 4] [-5 -3 -1 1 3]]
(let [s (range 10)] (->> s (map inc) (filter even?) (take 3)))
(2 4 6)
(let [s1 [1 2] s2 [1 2]] (identical? (rest s1) (rest s2)))
false(let [a 1] (eval `(~(fn [b] (+ 1 b)) 2)))
3(let [lst (range 10)] (zipmap lst (map #(* % -1) lst)))
{0 0, 1 -1, 2 -2, 3 -3, 4 -4, 5 -5, 6 -6, 7 -7, 8 -8, 9 -9}
(let [[a b] (split-at 2 [0 1 2 3])] (concat b a))
(2 3 0 1)
(defn foo [n] (let [a (atom n)] #(swap! a + %)))
#'user/foo
(let [m {:one 1, :two 2}] (for [k (keys m)] (prn k)))
(nil nil)
":one\n:two\n"(let [basic-car {:wheels 4}] [(assoc basic-car :egine :v8) (assoc basic-car :seats :leather)])
[{:egine :v8, :wheels 4} {:seats :leather, :wheels 4}]
(let [{f1 :foo, b1 :bar} {:foo 1, :bar 2}] (list f1 b1))
(1 2)
(def m (let [vals [:a :b :c]] (zipmap vals (rest (cycle vals)))))
#'user/m
(let [*foo* 2] ((with-local-vars [*foo* 3] (do (print @*foo*) (fn [] (print @*foo*))))))
nil"3nil"(let [[a b & [c]] [1 2 3]] (list a b c))
(1 2 3)
(let [m {:thinga [{:a1 "x", :a2 "y"}]} {[first-img] :thinga} m] first-img)
{:a1 "x", :a2 "y"}
(let [latin1 (apply str (range 32 255))] (apply str (re-seq #"\w" latin1)))
"323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618...
(let [state (atom {})] (defn stateful [k v] (swap! assoc state k v)))
#'user/stateful
(let [{:as x} nil {:as y} [] {:as z} ()] [x y z])
[nil [] {}]
(let [a 1 b (inc a)] (+ a a b b b))
8(let [[l r] ((juxt take drop) 3 (range 10))] (concat r l))
(3 4 5 6 7 8 9 0 1 2)
(let [pos (.lastIndexOf "this:is:a:string" ":")] [(subs "this:is:a:string" 0 pos) (subs "this:is:a:string" pos)])
["this:is:a" ":string"]
(let [x (rest (cons 1 (lazy-seq (do (print "hi") '(5)))))] 'ok)
ok(let [a 1 b 2] {:quoted '(a b), :unquoted [a b]})
{:quoted (a b), :unquoted [1 2]}
((fn [& a] (let [b (apply (hash-map) a)] :one b)) :one 2)
2(let [xs (cons 1 (lazy-seq (println "forced") '(2)))] (next xs) :foo)
:foo"forced\n"(let [cur *ns* alien (namespace 'alien)] (in-ns alien) (println *ns*) (in-ns cur))
nil"#object[sci.impl.vars.SciNamespace 0x6e468481 ]\n"(defmacro dbg [x] `(let [x# ~x] (println '~x "=" x#) x#))
#'user/dbg
(let [good (gensym) bad (symbol (str "abc" "xyz"))] `(vector ~good ~bad))
(clojure.core/vector G__3284229 abcxyz)
(let [{:keys [l]} '(:l "list") {:keys [v]} [:v "vector"]] [l v])
["list" nil]
(let [adder (fn [x] (fn [y] (+ x y)))] ((adder 3) 4))
7(let [f (fn [x & y] x)] (apply f (doall (range 1000000))))
0(let [x (map print [1 2 3 4 5 6 7])] nil)
nil(let [[f & r] (seq #{10 20 30})] (println f r))
nil"20 (30 10)\n"(let [a-fn (fn [x] (map inc x))] (-> [1 2 3] a-fn))
(2 3 4)
(let [s (list 1 2 3)] (identical? (cons 1 (rest s)) s))
false(let [{a :a, b :b} (seq [:a 1 :b 2])] [a b])
[1 2]
(let [a [1 2 3]] (case a [1 _ 3] "ok" "oops"))
"oops"(defmacro maze-thread [& xs] `(let [~'% ~@(interpose '% xs)] ~'%))
#'user/maze-thread
(let [m {:bar 4}] (identical? m (assoc m :bar 5 :bar 4)))
false(let [[a b c] (re-seq #".a." "happy and sad")] [c b a])
["sad" " an" "hap"]
(let [space " "] (concat "I" space "worship" space "His" space "shadow"))
(\I \space \w \o \r \s \h \i \p \space \H \i \s \space \s \h \a \d \o \w)
(let [map-a {:a 1} map-b {:a 1, :b 2}] (clojure.set/subset? map-a map-b))
false(let [data (atom {:a #{"a"}})] (swap! data update-in [:a] conj "b"))
{:a #{"a" "b"}}
(let [fullname (fn [sym] (str (namespace sym) "/" (name sym)))] (fullname :foo/bar))
"foo/bar"(let [north [-1 0] pos [8 3]] (map + north pos))
(7 3)
(let [f (fn [x & y] x)] (apply f (iterate inc 0)))
0

