Skip to content

Instantly share code, notes, and snippets.

View frenchy64's full-sized avatar

Ambrose Bonnaire-Sergeant frenchy64

  • Madison, Wisconsin
View GitHub Profile
@weissjeffm
weissjeffm / loop-with-timeout.clj
Created November 15, 2010 22:11
Clojure macro to insert timeouts into loops
;;Code rewriting macro
(defmacro loop-with-timeout [timeout bindings & forms]
`(let [starttime# (System/currentTimeMillis)]
(loop ~bindings
(if (> (- (System/currentTimeMillis) starttime#) ~timeout)
(throw (RuntimeException. (str "Hit timeout of " ~timeout "ms.")))
(do ~@forms)))))
;;example use of macro
(loop-with-timeout 60000 []
@ato
ato / debug.clj
Created December 9, 2009 11:42
Simpler debug-repl that works with unmodified Clojure
;; Inspired by George Jahad's version: http://georgejahad.com/clojure/debug-repl.html
(defmacro local-bindings
"Produces a map of the names of local bindings to their values."
[]
(let [symbols (map key @clojure.lang.Compiler/LOCAL_ENV)]
(zipmap (map (fn [sym] `(quote ~sym)) symbols) symbols)))
(declare *locals*)
(defn eval-with-locals