Clojure 在REPL中重新加载命名空间时获取IllegalStateException
我的命名空间声明如下所示:Clojure 在REPL中重新加载命名空间时获取IllegalStateException,clojure,read-eval-print-loop,Clojure,Read Eval Print Loop,我的命名空间声明如下所示: (ns test.foo (:use [clj-http.client :only (get) :as client] [net.cgrand.enlive-html :only (select) :as html])) 我第一次使用它时,它在REPL中工作得很好。然后,当我修改代码并在REPL中尝试以下操作时: (use :reload 'test.foo) 我得到: java.lang.IllegalStateException: get
(ns test.foo
(:use
[clj-http.client :only (get) :as client]
[net.cgrand.enlive-html :only (select) :as html]))
我第一次使用它时,它在REPL中工作得很好。然后,当我修改代码并在REPL中尝试以下操作时:
(use :reload 'test.foo)
我得到:
java.lang.IllegalStateException: get already refers to: #'clj-http.client/get in namespace: test.foo (foo.clj:1)
我使用逆时针方向的windows,也尝试使用leiningen(lein repl)。您不应该意外地对核心FN进行阴影处理。你必须明确你的意图:
(ns test.foo
(:refer-clojure :exclude [get]) ; suppress the shadowing warning
(:require [clojure.core :as core]) ; allow to still reach clojure.core/get through core/get
(:use
[clj-http.client :only (get) :as client]
[net.cgrand.enlive-html :only (select) :as html]))
非常感谢你,克里斯托弗。我想我不可能指望比Clojure大师更好地回答我的问题;o) 虽然这个答案仍然完全正确,但我意识到使用:require而不是:use也解决了我的问题,只要我始终使用:as中指定的前缀从其他名称空间调用函数。我个人更喜欢这个选择。