在 REPL 中重新加载命名空间时出现 IllegalStateException

发布于 2024-10-11 03:28:41 字数 485 浏览 10 评论 0原文

我的命名空间声明如下所示:

(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)。

My namespace declaration looks like this:

(ns test.foo
  (:use 
    [clj-http.client :only (get) :as client]
    [net.cgrand.enlive-html :only (select) :as html]))

It works fine in the REPL, the first time I use it. Then, when I modify the code and try the following in the REPL:

(use :reload 'test.foo)

I get:

java.lang.IllegalStateException: get already refers to: #'clj-http.client/get in namespace: test.foo (foo.clj:1)

I'm on windows with counterclockwise and also tried with leiningen (lein repl).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦初启 2024-10-18 03:28:41

您不应该意外地隐藏核心 fns。您必须明确表达您的意图:

(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]))

You should not shadow core fns by accident. You have to be explicit about your intent:

(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]))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文