Skip to content

Instantly share code, notes, and snippets.

@ticean
Last active July 14, 2018 22:39
Show Gist options
  • Save ticean/49ee4491e2c5c235b849cd06d3a435fa to your computer and use it in GitHub Desktop.
Save ticean/49ee4491e2c5c235b849cd06d3a435fa to your computer and use it in GitHub Desktop.
Lil' Nestable Clojure REPL
(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