Why do I lose all symbols when using in-ns to move

2020-04-17 07:22发布

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?

1条回答
做个烂人
2楼-- · 2020-04-17 07:36

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:

  1. Use ns instead of in-ns, like so: (ns my-namespace.core)
  2. Refer clojure.core, like so: (clojure.core/refer-clojure)
查看更多
登录 后发表回答