Last active
July 20, 2018 09:41
-
-
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.
This file contains 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 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