Last active
August 29, 2015 14:11
-
-
Save mnzk/88168bd25656c3fcb96e to your computer and use it in GitHub Desktop.
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
(ns program | |
(:import System.IO.EndOfStreamException) | |
(:import clojure.lang.Compiler+CompilerException) | |
(:gen-class)) | |
(defn try-eval [line v] | |
(let [v (conj v (str "\n" line))] | |
(try | |
[true (-> (apply str v) read-string eval) []] | |
(catch EndOfStreamException e [false nil v]) | |
(catch Compiler+CompilerException e [true e []]) | |
(catch Exception e [true e []])))) | |
(defn start-repl [] | |
(loop [pool-vec []] | |
(binding [*print-dup* false] | |
(print (str *ns* "=> "))) | |
(let [line (read-line)] | |
(cond | |
(= ":q" line) nil | |
:else (let [[print? val pool-vec] (try-eval line pool-vec)] | |
(when print? (println val)) | |
(recur pool-vec)))))) | |
(defn -main [& args] | |
(binding [*ns* *ns* ;;'user | |
*flush-on-newline* true ;;*flush-on-newline* | |
*print-length* 2000 ;;*print-length* | |
*print-dup* *print-dup* | |
*print-level* 100 ;;*print-level* | |
*print-meta* *print-meta* | |
*print-readably* *print-readably* | |
*read-eval* *read-eval* | |
*unchecked-math* *unchecked-math* | |
*data-readers* *data-readers* | |
*default-data-reader-fn* *default-data-reader-fn* | |
*warn-on-reflection* *warn-on-reflection* | |
] | |
(in-ns 'user) | |
(start-repl))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment