Skip to content

Commit

Permalink
flag to control eval reader (*read-eval*) [issue 34], patch from jhawk28
Browse files Browse the repository at this point in the history
  • Loading branch information
richhickey committed Apr 12, 2009
1 parent 0a8ac6b commit ac2374f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/clj/clojure/core.clj
Expand Up @@ -4019,6 +4019,13 @@
Defaults to true")

(add-doc *read-eval*
"When set to logical false, the EvalReader (#=(...)) is disabled in the
read/load in the thread-local binding.
Example: (binding [*read-eval* false] (read-string \"#=(eval (def x 3))\"))
Defaults to true")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; helper files ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(alter-meta! (find-ns 'clojure.core) assoc :doc "Fundamental library of the Clojure language")
(load "core_proxy")
Expand Down
5 changes: 5 additions & 0 deletions src/jvm/clojure/lang/LispReader.java
Expand Up @@ -903,6 +903,11 @@ else if(s.ns != null) //static method

public static class EvalReader extends AFn{
public Object invoke(Object reader, Object eq) throws Exception{
if (!RT.booleanCast(RT.READEVAL.deref()))
{
throw new Exception("EvalReader not allowed when *read-eval* is false.");
}

PushbackReader r = (PushbackReader) reader;
Object o = read(r, true, null, true);
if(o instanceof Symbol)
Expand Down
1 change: 1 addition & 0 deletions src/jvm/clojure/lang/RT.java
Expand Up @@ -178,6 +178,7 @@ public class RT{
new PrintWriter(new OutputStreamWriter(System.err, UTF8), true));
final static Keyword TAG_KEY = Keyword.intern(null, "tag");
final static public Var AGENT = Var.intern(CLOJURE_NS, Symbol.create("*agent*"), null);
final static public Var READEVAL = Var.intern(CLOJURE_NS, Symbol.create("*read-eval*"), T);
final static public Var MACRO_META = Var.intern(CLOJURE_NS, Symbol.create("*macro-meta*"), null);
final static public Var MATH_CONTEXT = Var.intern(CLOJURE_NS, Symbol.create("*math-context*"), null);
static Keyword LINE_KEY = Keyword.intern(null, "line");
Expand Down

0 comments on commit ac2374f

Please sign in to comment.