4

I have this clojure file:

(ns foo.core)

(def bar 1)

And this project.clj:

(defproject foo "version"
  :dependencies [[org.clojure/clojure "1.6.0"]]
  :main foo.core)

I open a terminal and run lein repl. Then I change the value of bar OUTSIDE the repl.

(def bar 1) 

to

(def bar 2)

I change this value on the editor and don't forget to save the file. Then I run the command in the repl (load-string "(clojure.tools.namespace.repl/refresh)") I type bar in the repl and still get 1 instead of 2. However if you just run (clojure.tools.namespace.repl/refresh) and then query the value of bar you get 2. Why is this so? Why is the function load-string breaking it?

2 Answers 2

2

Apparently, specifying a :main in your project.clj forces the project to use AOT which breaks this.

Source: http://dev.clojure.org/jira/browse/TNS-27

Sign up to request clarification or add additional context in comments.

1 Comment

rm -r target/ - Apparently, some artifact was left behind when I compiled with aot, so even when I removed it from my project.clj, it was still giving an error like OPs. So so so annoying, thanks for helping me isolate it @acron!
0

It's not how your invoking refresh, it's when you invoke it.

refresh uses timestamps on files to see when it needs to reload them. This way it only reloads things it needs to. Because you didn't change the file after redefining a var through the repl, it skipped loading that file.

if I start with a file like this:

(ns bla.core)  
(def bar 3) 

and then call refresh the first time:

bla.core> (load-string"(clojure.tools.namespace.repl/refresh)")
:reloading (bla.core bla.core-test)
:ok

then redefine bar in the repl:

bla.core> (def bar :changed-from-repl)                                             
#'bla.core/bar

and refresh again:

bla.core> (load-string "(clojure.tools.namespace.repl/refresh)")
:reloading ()
:ok

we can see that it didn't reload any namespaces.

1 Comment

I edited my question to make it clearer. I actually change the value of bar outside the repl. I did that in an editor and save the file afterwards.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.