We're updating the issue view to help you get more done. 

clojure.main/repl unconditionally refers REPL utilities into *ns*

Description

A number of vars from clojure.repl, clojure.java.javadoc, and clojure.pprint are unconditionally referred into ns by clojure.main/repl. This is fine when it is being used e.g. as the primary driver of a terminal-bound Clojure REPL, but other usages can end up bringing those utility vars into namespaces other than 'user. This can cause problems if clojure.main/repl is used to drive a REPL within namespaces that already have referred or interned vars with the same names as those utility vars, e.g.:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 $ java -jar ~/.m2/repository/org/clojure/clojure/1.5.0-alpha6/clojure-1.5.0-alpha6.jar Clojure 1.5.0-alpha6 user=> (ns foo) nil foo=> (defn pp [] "hi!") #'foo/pp foo=> (pp) "hi!" foo=> (clojure.main/repl) foo=> (pp) nil nil foo=> (defn pp [] "whoops") CompilerException java.lang.IllegalStateException: pp already refers to: #'clojure.pprint/pp in namespace: foo, compiling:(NO_SOURCE_PATH:7:1)

Worse, nREPL uses clojure.main/repl (in large part to maximize the consistency of REPL behaviour across different Clojure versions), where each user expression is evaluated through a separate clojure.main/repl invocation. This leads to the same problems as above, but for every nREPL user, session, and expression (reported @ NREPL-31).

A simple fix for this is to perform these refers only if ns is 'user (which, AFAICT, was the only intended effect of CLJ-310, CLJ-454, and https://github.com/clojure/clojure/commit/04764db, the changes that added these automatic implicit refers to clojure.main/repl).

Environment

None

Status

Assignee

Unassigned

Reporter

Chas Emerick

Labels

None

Approval

Ok

Patch

Code

Fix versions

Affects versions

Release 1.5
Release 1.4

Priority

Major