In a lein repl, whenever I do
(in-ns 'some-namespace-other-than-name.core)
clojure.core is not included by default.
To explain, initially I found myself getting caught by this like so
db.core=> (in-ns 'db.seed)
#object[clojure.lang.Namespace 0x12738ef5 "db.seed"]
db.seed=> (use 'environ.core)
Syntax error compiling at (form-init7774277424301430706.clj:1:1).
Unable to resolve symbol: use in this context
I just found how to fix this:
db.seed=> (clojure.core/use 'clojure.core)
nil
db.seed=> (use 'environ.core)
nil
My question is, it seems that clojure.core is included automatically in the namespace myapp.core, but not in any other namespaces i might switch to in the repl. (yet, obviously those namespaces do have access to clojure.core when i run the program from the core namespace).
Is that just a leiningen default?
Wondering what piece of understanding or usage I'm missing here.
Is it that when we run a program, only myapp.core needs access to clojure.core, and the namespaces your .core will utilise do not themselves need access to clojure.core, because they are, when executed, merely imports into your app's .core? Hence switching to some other namespace to run things is in essence a bit artificial?
I looked at the docs for the :main key in project.clj but couldn't find an answer.
refer-clojure
, see the explanation here: clojure.org/guides/repl/… – glts(clojure.core/refer-clojure)
seems to have similar effect to issuing(clojure.core/use 'clojure.core)
, when in a namespace where core is absent. – mwal(require 'db.series :verbose :reload)
to reload a file I've been working on, then simply call functions in that other (now reloaded) namespace always by fully qualifying them, like(pprint (db.series/app-state ...))
, i.e. not bothering to switch to the other namespace at all. At least this works without surprises. – mwal