【问题标题】:Getting IllegalStateException when reloading a namespace in the REPL在 REPL 中重新加载命名空间时出现 IllegalStateException
【发布时间】:2011-01-10 15:53:27
【问题描述】:

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

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

我在逆时针窗口上,也尝试过 leiningen (lein repl)。

【问题讨论】:

    标签: clojure read-eval-print-loop


    【解决方案1】:

    您不应意外影响核心 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]))
    

    【讨论】:

    • 非常感谢克里斯托夫。我想我不能期望比 Clojure 大师回答我的问题更好;o)
    • 虽然这个答案仍然完全有效,但我意识到使用 :require 而不是 :use 也可以解决我的问题,只要我总是使用 :as 中指定的前缀从其他命名空间调用函数.我个人更喜欢这种选择。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-10
    • 2012-04-26
    • 1970-01-01
    • 2011-10-23
    • 2011-09-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多