I am just starting out learning Clojure and Emacs. I have got Clojure Box for windows running and I would like to be able to write code in a buffer then run it in the REPL without haveing to call
(use 'example.code)
all the time. I know about C-c C-k but it doesn’t reload the namespace. If i use
(in-ns 'example.code)
to change namespace in the repl it works. What is the right way to do this?
in-nsis one of the right ways.The way which feels most “right” to me is to
(require '[example.code :as ec])and work in theusernamespace at the REPL; that way my throwaway experimental state stays inuserandec/foois convenient enough to me (and it makes it obvious wherefoois supposed to come from). You can always say(require :reload-all 'example.code)(same works withuse) to force recompilation.Also, here’s a function to remove (from the current namespace) all mappings pulled in from a given namespace with
use:On top of that you could build
and say
(reuse 'example.code)to get something close to a fresh start with your namespace. (Note that 1.2 new features such asdeftype&defrecordintroduce some complexities… In particular,unusehas no effect onimported class — this includes records anddeftype-created types.:reload-allstill causes thedeftypeet al. forms to be recompiled, but I remember hitting weird cases where this didn’t seem to be enough… Possibly my error, possibly some arcane aspect of these features I haven’t yet fully explored.)