reloaded.repl icon indicating copy to clipboard operation
reloaded.repl copied to clipboard

Reloading not working as expected

Open pedroteixeira opened this issue 7 years ago • 3 comments

Hello! For some reason I'm struggling a bit with hot reloading code from repl in a new project setup (lein).

in user.clj

(reloaded.repl/set-init!
  #(make-system {}))

but (reset) does not pick up changes (no change that I've could detect, after modifying stop and start component protoocols for ex, nor in web routes in the particular case I'm trying to impl)

Tried diffferent many things past in the hour (setting refresh dirs, using deref for the make-system symbol, etc) but the only way I managed to reload the code as I expected was to use this (refresh) function:

(defn refresh
  []
  (tools-ns/refresh-all)
  (reloaded.repl/set-init!
    #(make-system {}))
  (init)
  (go))

Not sure if here is the best place to ask, but if you some have some tips or experiene with related issues, I'd appreciate :)

pedroteixeira avatar Jul 05 '17 19:07 pedroteixeira

Could you provide a little more information? What's in make-system, for example? What does your project file look like? If you could set up a small project where the problems you're seeing could be reproduced, that would help a lot.

weavejester avatar Jul 05 '17 20:07 weavejester

Hello James,

4 years after is never too late I guess... I was able to reproduce the reported issue.

Environment (somewhat irrelevant in that case):

* Java: OpenJDK Runtime Environment (build 11.0.10+9-Ubuntu-0ubuntu1.20.04)
* Leiningen 2.9.1 on Java 11.0.10 OpenJDK 64-Bit Server VM
* Editor: GNU Emacs 27.1
* CIDER: 1.1.0snapshot

History

  1. Cloning repository: https://github.com/arnaudgeiser/reloaded.repl-issue-12
  2. Firing REPL (cider-jack-in)
  3. Loading the following namespace : https://github.com/arnaudgeiser/reloaded.repl-issue-12/blob/master/src/reloaded/repl_issue_12.clj
  4. Evaluating these expressions
(set-init! #(new-system))
(go)
  1. Creating new system is printed
  2. Changing the following function definition (!!without evaluating it in the REPL!!)
(defn new-system []
  (prn "Recreating new system")
  (component/system-map))
  1. Evaluating this expression
(reset)
  1. Creating new system is printed

Expectation

Expected to see Recreating new system printed. However, it seems that clojure.tools.namespace.repl/refresh is not the same as redefining the function in the REPL.

Actual

new-system is always bounded to the previous definition

Impact

While it's surprising, the workaround is quite simple :

(reset)
(set-init! #(new-system))
(go)

arnaudgeiser avatar May 17 '21 18:05 arnaudgeiser