Why doesn't Clojure provide a standard library after creating a new namespace?

I ran into this problem after creating a new namespace.

Here is the code:

(create-ns 'my-new-ns)
=> #object[clojure.lang.Namespace 0x7c7c8359 "my-new-ns"]

(in-ns 'my-new-ns)
=> #object[clojure.lang.Namespace 0x7c7c8359 "my-new-ns"]

(reduce + [1 2 3])
CompilerException java.lang.RuntimeException: Unable to resolve symbol: reduce in this context, compiling:(/private/var/folders/pg/bynypsm12nx1s4gzm56mwtcr0000gn/T/form-init1425759900088902804.clj:1:1) 

As you can see, the function is reducenot defined in the namespace my-new-ns.

Should I be able to create new namespaces, so what would be the best solution for this problem?

PS: In addition, I am trying to create these namespaces for my users so that they can do whatever they want in their namespaces (the idea is like a container) and create isolation between namespaces.

+4
source share
4

clojure.core , . ns :

  • - create-ns
  • - in-ns
  • clojure.core vars - refer-clojure

( - ), , , :

(clojure.core/refer-clojure)
+6

, , ns. :

* ns * ( ), .

vars clojure.core .

,

> (create-ns 'my-new-ns)
> (in-ns 'my-new-ns)
> (clojure.core/refer 'clojure.core)

> (ns my-new-ns)

Update:

: refer , :

> (create-ns 'x)
> (in-ns 'x)
> reduce ;; throws "Unable to resolve symbol"
> clojure.core/reduce ;; works fine

, (clojure.core/refer 'clojure.core).

+5

"" , . , java.lang, clojure.lang.Compiler clojure.core.

+1

,

(ns my-new-ns)

. create-ns - .

+1

Source: https://habr.com/ru/post/1666984/


All Articles