Last active
July 14, 2018 22:39
-
-
Save ticean/49ee4491e2c5c235b849cd06d3a435fa to your computer and use it in GitHub Desktop.
Lil' Nestable Clojure REPL
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
(def ^:dynamic repl-context) | |
(defn tinyrepl | |
"Simple REPL. :quit to exit." | |
[{:keys [prefix layer] :or {prefix "" layer 1} :as context}] | |
(let [pre (str prefix ">>>")] | |
(with-bindings {#'repl-context (assoc context | |
:prefix pre | |
:layer (inc layer))} | |
(print (str (ns-name *ns*) (str pre " "))) | |
(flush) | |
(let [expr (read) | |
value (eval expr)] | |
(when (not= :quit value) | |
(println value) | |
(recur)))))) | |
(comment | |
; Example | |
dev=> (tinyrepl {}) | |
dev>>> (tinyrepl repl-context) | |
dev>>>>>> (tinyrepl repl-context) | |
dev>>>>>>>>> (+ 1 1) | |
2 | |
dev>>>>>>>>> :quit | |
nil | |
dev>>>>>> :quit | |
nil | |
dev>>> :quit | |
nil | |
dev=> | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment