簡體   English   中英

clojure.tools.namespace刷新所有后clojure.repl命名空間丟失

[英]clojure.repl namespace lost after clojure.tools.namespace refresh-all

我不確定這是預期還是錯誤,但在運行(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項目來啟動命名空間user的repl並導入其他命名空間 - 而不是從項目命名空間(由:main定義)開始。

所以我在我的project.clj添加了:repl-options {:init-ns user}並創建了一個項目user.clj - 確保我需要的clojure.repl函數始終可用 - 如Stuart Sierra的帖子“My 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

這是一種解決方法,而不是對行為的真正修復或解釋。 另一種方法可能是確保

clojure.tools.namespace.repl/refresh-all工作原理是在加載新命名空間之前銷毀命名空間的內存版本中的當前版本。 由於doc函數在啟動時由REPL插入而未在源文件中定義,因此在重新加載時會丟失。

你可以使用函數disable-unload! 並禁用重新加載! clojure.tools.namespace.repl以防止刷新自動取消/重新加載名稱空間。 nREPL在初始命名空間中插入輔助函數(如doc ),默認情況下是應用程序的主命名空間。 您可以通過在Leiningen配置文件中設置備用初始命名空間來確保將這些函數插入其他位置。

我還建議為命名空間創建一個實際的源文件,該文件包含在REPL中使用的輔助函數。 您可以在我的其他答案中找到有關如何執行此操作的說明。

可以在我的Github上找到示例用戶配置文件設置

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM