How to reload a clojure file in REPL

后端 未结 8 1041
忘了有多久
忘了有多久 2020-12-02 03:41

What is the preferred way of reloading functions defined in a Clojure file without having to restart the REPL. Right now, in order to use the updated file I have to:

相关标签:
8条回答
  • 2020-12-02 04:11

    The best answer is:

    (require 'my.namespace :reload-all)
    

    This will not only reload your specified namespace, but will reload all dependency namespaces as well.

    Documentation:

    require

    0 讨论(0)
  • 2020-12-02 04:13

    Or (use 'your.namespace :reload)

    0 讨论(0)
  • 2020-12-02 04:17

    As soon as (use 'foo.bar) works for you, it means that you have foo/bar.clj or foo/bar_init.class on your CLASSPATH. The bar_init.class would be an AOT-compiled version of bar.clj. If you do (use 'foo.bar), I'm not exactly sure if Clojure prefers class over clj or the other way round. If it would prefer class files and you have both files, then it's clear that editing the clj file and then reloading the namespace has no effect.

    BTW: You don't need to load-file before the use if your CLASSPATH is set properly.

    BTW2: If you need to use load-file for a reason, then you can simply do it again if you edited the file.

    0 讨论(0)
  • 2020-12-02 04:19

    One liner based on papachan's answer:

    (clojure.tools.namespace.repl/refresh)
    
    0 讨论(0)
  • 2020-12-02 04:27

    There is also an alternative like using tools.namespace, it's pretty efficient:

    user=> (use '[clojure.tools.namespace.repl :only (refresh)])
    
    user=> (refresh)
    
    :reloading (namespace.app)
    
    :ok
    
    0 讨论(0)
  • 2020-12-02 04:28

    Try load-file again?

    If youre using an IDE, there's usually a keyboard shortcut to send a code-block to the REPL, thus effectively re-defining the associated functions.

    0 讨论(0)
提交回复
热议问题