Skip to content

Instantly share code, notes, and snippets.

@mnzk
Last active August 29, 2015 14:11
Show Gist options
  • Save mnzk/88168bd25656c3fcb96e to your computer and use it in GitHub Desktop.
Save mnzk/88168bd25656c3fcb96e to your computer and use it in GitHub Desktop.
(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