Clojure: How to to recur upon exception?

Macros are calling… How about this: (defn try-times* “Executes thunk. If an exception is thrown, will retry. At most n retries are done. If still some exception is thrown it is bubbled upwards in the call chain.” [n thunk] (loop [n n] (if-let [result (try [(thunk)] (catch Exception e (when (zero? n) (throw e))))] (result … Read more

Clojure – difference between ‘ (apostrophe) and ` (backtick)

When you quote a collection with ‘, the symbol-name will be quoted exactly as you enter it. ‘(+ x x) => (+ x x) (map namespace *1) => (nil nil nil) ‘(bingo/+ lara/y user/z) => (bingo/+ lara/y user/z) (map namespace *1) => (“bingo” “lara” “user”) When you quote a collection with the backtick, it tries … Read more

Clojure multimethods vs. protocols

Protocol and multimethods are complementary and intended for slightly different use cases. Protocols provide efficient polymorphic dispatch based on the type of the first argument. Because the is able to exploit some very efficient JVM features, protocols give you the best performance. Multimethods enable very flexible polymorphism which can dispatch based on any function of … Read more

Any way to add dependency to lein project without REPL restart?

You can use Alembic, a dynamic classpath loader and dependencies resolver. The good thing is that it doesn’t load all pomegranate dependencies. Add the following to your .lein/profiles.clj: {:user {:dependencies [[alembic “0.3.2”]]}} Then in your Repl just load the classpaths you need, they will be pulled from the repositories by leinif need: (require ‘alembic.still) (alembic.still/distill … Read more