Skip to content
Browse files

CLJ-1168: bind *read-eval* to "known" value for all REPL reads

  • Loading branch information...
1 parent 68c4962 commit 4526952c9548f0d4983caedbb82c4741f461acd5 @stuarthalloway stuarthalloway committed Feb 22, 2013
Showing with 10 additions and 4 deletions.
  1. +10 −4 src/clj/clojure/main.clj
View
14 src/clj/clojure/main.clj
@@ -183,6 +183,13 @@ by default when a new command-line REPL is started."} repl-requires
[clojure.java.javadoc :refer (javadoc)]
[clojure.pprint :refer (pp pprint)]])
+(defmacro with-read-known
+ "Evaluates body with *read-eval* set to a \"known\" value,
+ i.e. substituting true for :unknown if necessary."
+ [& body]
+ `(binding [*read-eval* (if (= :unknown *read-eval*) true *read-eval*)]
+ ~@body))
+
(defn repl
"Generic, reusable, read-eval-print loop. By default, reads from *in*,
writes to *out*, and prints exception summaries to *err*. If you use the
@@ -247,8 +254,7 @@ by default when a new command-line REPL is started."} repl-requires
(fn []
(try
(let [read-eval *read-eval*
- input (binding [*read-eval* (if (= :unknown read-eval) true read-eval)]
- (read request-prompt request-exit))]
+ input (with-read-known (read request-prompt request-exit))]
(or (#{request-prompt request-exit} input)
(let [value (binding [*read-eval* read-eval] (eval input))]
(print value)
@@ -297,12 +303,12 @@ by default when a new command-line REPL is started."} repl-requires
[str]
(let [eof (Object.)
reader (LineNumberingPushbackReader. (java.io.StringReader. str))]
- (loop [input (read reader false eof)]
+ (loop [input (with-read-known (read reader false eof))]
(when-not (= input eof)
(let [value (eval input)]
(when-not (nil? value)
(prn value))
- (recur (read reader false eof)))))))
+ (recur (with-read-known (read reader false eof))))))))
(defn- init-dispatch
"Returns the handler associated with an init opt"

0 comments on commit 4526952

Please sign in to comment.
Something went wrong with that request. Please try again.