Skip to content

Instantly share code, notes, and snippets.

@saikyun
Last active July 20, 2018 09:41
Show Gist options
  • Save saikyun/ebc60b9216c76a0eef9950cdd8bca647 to your computer and use it in GitHub Desktop.
Save saikyun/ebc60b9216c76a0eef9950cdd8bca647 to your computer and use it in GitHub Desktop.
Taken from Joy of Clojure by Fogus and Houser. Use (break) to get a repl in the spot were break was called.
(defn contextual-eval [ctx expr]
(eval
`(let [~@(mapcat (fn [[k v]] [k `'~v]) ctx)]
~expr)))
(defn readr [prompt exit-code]
(let [input (clojure.main/repl-read prompt exit-code)]
(if (= input ::tl)
exit-code
input)))
(defmacro local-context []
(let [symbols (keys &env)]
(zipmap (map (fn [sym] `(quote ~sym)) symbols) symbols)))
(defmacro break []
`(clojure.main/repl
:prompt #(print "debug=> ")
:read readr
:eval (partial contextual-eval (local-context))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment