This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(do | |
(ns guzheng.sample) | |
(defn | |
do-hello | |
[] | |
(println "hello") | |
(if | |
true | |
(clojure.core/let | |
[count__782__auto__ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn rate-limit [interval s] | |
(let [cache (atom {})] | |
(->> s | |
(map #(vector % (System/currentTimeMillis))) | |
(filter (fn [[x t]] (< (+ (get @cache x 0) interval) t))) | |
(map (fn [[x t]] (swap! cache assoc x t) x))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(->> (iterate (partial prewalk-replace expansions) unexpanded) | |
(mapcat #(vector % %)) | |
drop | |
(partition 2) | |
(take-while (fn [[x y]] (not= x y)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro defn-errors | |
"Like defn, but allows any number of the | |
argument to throw errors, using join-errors" | |
[name & args] | |
(let [[name [params & body]] (name-with-attributes | |
name args) | |
param-sym (gensym "params")] | |
`(defmacro ~name [& ~param-sym] | |
`(apply (fn [~@'~params] ~@'~body) | |
(join-errors |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def ^:dynamic foo nil) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def #^:dynamic foo 0) | |
(def my-bound-fn | |
(binding [foo 22] | |
(bound-fn [name] | |
(println "Hi" name "foo is" foo))) | |
(assert (= foo 0)) | |
(my-bound-fn "David") | |
(assert (= foo 0)) | |
;Prints "Hi David foo is 22" but called outside the binding! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(when-not (has-root-binding? (var name)) | |
(def name expr)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def ^:dynamic foo 0) | |
((binding [foo 22] | |
(bound-fn [name] | |
(println "Hi" name "foo is" foo))) "David") | |
(assert (= foo 0)) | |
(my-bound-fn "David") | |
(assert (= foo 0)) | |
;Prints "Hi David foo is 22" but called outside the binding! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def #^:dynamic foo nil) |
NewerOlder