Running the following code in a Leiningen REPL:
(in-ns 'my-namespace.core)
(+ 2 2)
results in this error:
CompilerException java.lang.RuntimeException: Unable to resolve symbol: + in this context
Why?
Running the following code in a Leiningen REPL:
(in-ns 'my-namespace.core)
(+ 2 2)
results in this error:
CompilerException java.lang.RuntimeException: Unable to resolve symbol: + in this context
Why?
When you create a new namespace using in-ns
, the core namespace (clojure.core
) is not referred by default. "Referring" a namespace means including it in your namespace in such a way that you can refer to that namespace's symbols as your own.
It is still possible to use symbols from clojure.core
using fully qualified names, like so:
(clojure.core/+ 2 2)
The solution is to either:
ns
instead of in-ns
, like so: (ns my-namespace.core)
clojure.core
, like so: (clojure.core/refer-clojure)