How to reload a clojure file in REPL

后端 未结 8 1211
忘了有多久
忘了有多久 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 04:31

    I use this in Lighttable (and the awesome instarepl) but it should be of use in other development tools. I was having the same problem with old definitions of functions and multimethods hanging around after reloads so now during development instead of declaring namespaces with:

    (ns my.namespace)
    

    I declare my namespaces like this:

    (clojure.core/let [s 'my.namespace]
                      (clojure.core/remove-ns s)
                      (clojure.core/in-ns s)
                      (clojure.core/require '[clojure.core])
                      (clojure.core/refer 'clojure.core))
    

    Pretty ugly but whenever I re-evaluate the entire namespace (Cmd-Shift-Enter in Lighttable to get the new instarepl results of each expression), it blows away all old definitions and gives me a clean environment. I was tripped up every few days by old definitions before I started doing this and it has saved my sanity. :)

提交回复
热议问题