我不知道如果这是预期或错误,但在运行后(clojure.tools.namespace.repl/refresh-all)的clojure.repl命名空间丢失。
nREPL server started on port 61579 on host 127.0.0.1 nrepl://127.0.0.1:61579
REPL-y 0.3.5, nREPL 0.2.7
Clojure 1.6.0
testbed.core=> (doc map)
-------------------------
clojure.core/map
([f coll] [f c1 c2] [f c1 c2 c3] [f c1 c2 c3 & colls])
Returns a lazy...
nil
testbed.core=> (require 'clojure.tools.namespace.repl)
nil
testbed.core=> (clojure.tools.namespace.repl/refresh-all)
:reloading (testbed.core testbed.core-test)
:ok
testbed.core=> (doc map)
CompilerException java.lang.RuntimeException: Unable to resolve symbol: doc in this context, compiling:(/private/var/folders/xs/jbvb_r6j07q8xtclwlcbm21h0000gn/T/form-init6764593924445976503.clj:1:1)
testbed.core=>
我的 project.clj 非常简单:
(defproject testbed "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.6.0"]]
  :main ^:skip-aot testbed.core
  :target-path "target/%s"
  :profiles {:uberjar {:aot :all}
             :dev {:dependencies [[org.clojure/tools.namespace "0.2.10"]]}})
有没有简单的方法可以避免这种情况?特别是在运行 Emacs/CIDER 时?
我记得有这个问题。虽然已经有一段时间了,但我记得通过设置我的 lein 项目来解决这个问题,以在命名空间中启动 repluser并导入其他命名空间 - 而不是从项目命名空间(由 定义:main)开始。
所以我添加:repl-options {:init-ns user}到我的project.clj并创建了一个项目user.clj- 确保clojure.repl我需要的功能始终可用 - 如 Stuart Sierra 的文章“我的 Clojure 工作流程,重新加载”中所述
会议:
user=> (doc +)
-------------------------
clojure.core/+
([] [x] [x y] [x y & more])
  Returns the sum of nums. (+) returns 0. Does not auto-promote
  longs, will throw on overflow. See also: +'
nil
user=> (clojure.tools.namespace.repl/refresh-all)
(...namespaces...)
user=> (doc +)
-------------------------
clojure.core/+
([] [x] [x y] [x y & more])
  Returns the sum of nums. (+) returns 0. Does not auto-promote
  longs, will throw on overflow. See also: +'
nil
这是一种变通方法,而不是对行为的真正修复或解释。另一种方法是确保