2

Lets say I have a code file that has the ns - (ns abc.a). Now I start my repl and am in the ns- (use-ns 'abc.a).

Now if I change any code in the file, how do I get to reload the ns in the repl?

Thanks, Murtaza

murtaza52
  • 46,887
  • 28
  • 84
  • 120

4 Answers4

5

You can hot reload the code with (require :reload 'abc.a) or (require :reload-all 'abc.a). The latter also reloads all the required namespaces of abc.a while the former only reloads abc.a.

kotarak
  • 17,099
  • 2
  • 49
  • 39
3

You can use load-file to reload the file.

Ankur
  • 33,367
  • 2
  • 46
  • 72
  • Interestingly, load-file does not set my name space in the [lien] REPL (Ubuntu 10.04). By that I mean, if I start out lein repl, ns is user, but if I load my file using (load-file src/xml_lib/core.clj) the ns does not change. I have to issue (ns xml_lib.core). – octopusgrabbus Jul 03 '12 at 13:41
2

When you set a namespace in REPL you don't load any code from the file where the namespace is defined. You need to execude all the code from the file (simplest way is copy-paste).

So if your file looks like this:

(ns abc.a)
(def x 3)

then after executing user=>(ns abc.a) in REPL you get the prompt abc.a=>. Your namespace is changed but there is nothing in it yet. Type x to see it is not defined. It is only after executing abc.a=>(def x 3), that you get your code loaded to the ns in REPL.

If you then change your x definition in file (say to (def x 5)), just type the new one in REPL to get this code reloaded.

If you're using emacs, I'd advise you to read this question.

Community
  • 1
  • 1
Paweł Łoziński
  • 1,094
  • 7
  • 8
  • After you configure emacs+slime it is enough to hit `C-x C-e` to get the code you've just written reloaded. I don't think people feel the need for anything quicker that this, so I wouldn't expect any automatic code-from-file-reloading-tools. However, if you want one - keep looking. – Paweł Łoziński Jul 03 '12 at 08:41
2

when using emacs and slime you can hit ctrl-c ctrl-l to reload the currend namespace and reload anything it includes.

Arthur Ulfeldt
  • 90,827
  • 27
  • 201
  • 284