Leiningen REPL not autoloading project.core namespace

814 views Asked by At

I'm new to Clojure so this could very well be an easy question. I'm having an issue with the REPL while using Leiningen.

Previously, I had created an app project while following a tutorial. When I would launch the REPL using lein repl with that project, it would always put me in the project's core namespace automatically. Even though I was in that namespace, I could still access built-in resources e.g. (doc build-in-function-name), etc.

Now, I've created another non-app project and I seem to have lost this autoloading capability. I'm now being put into a user namespace by default. Also, when I try to get access to my project's core namespace by doing (in-ns 'project.core), I lose access to build-in functions like doc.

Can anyone explain what's going on here?

1

There are 1 answers

1
noisesmith On BEST ANSWER

in-ns does not load code. It switches to an ns, creating it if needed. It also does not do the default ns setup (eg. referring clojure.core). The proper way to load a namespace from code in the repl is with require (require 'some.ns), which can then be followed by (in-ns 'some.ns) if it succeeds.

You can use the :repl-options {:init-ns some.ns} option in project.clj to specify the namespace that leiningen should auto-load into your repl. When it's up to me I do not use this option, because it prevents me from having a usable repl if there is any bug that prevents my code from loading.