Damien
Damien

Reputation: 2254

Getting IllegalStateException when reloading a namespace in the 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).

Upvotes: 14

Views: 3066

Answers (1)

cgrand
cgrand

Reputation: 7949

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

Upvotes: 9

Related Questions