英和訓練

著作権は原文に属します

Reference - Namespaces 名前空間

Namespaces are mappings from simple (unqualified) symbols to Vars and/or Classes. 名前空間は、シンプルな(修飾されていない)シンボルからVarおよび/またはClassへのマップである。Vars can be interned in a namespace, using def or any of its variants, in which case they have a simple symbol for a name and a reference to their containing namespace, and the namespace maps that symbol to the same var. Varらは、defやそれに類するものを用いることである名前空間にinternされうる。その場合には、Varは名前としてシンプルなシンボルを持ち、自身を含む名前空間を参照する。そしてその名前空間は、そのシンボルからそのvarへとマップする。A namespace can also contain mappings from symbols to vars interned in other namespaces by using refer or use, or from symbols to Class objects by using import. referないしuseが使われた場合には、名前空間はシンボルから、他の名前空間にinternされたvarへもマップする。また、importされた際には、名前空間はシンボルからClassへマップする。 Note that namespaces are first-class, they can be enumerated etc. 名前空間は第一級であるから、列挙等されうる。Namespaces are also dynamic, they can be created, removed and modified at runtime, at the Repl etc. 名前空間は動的でもある。よってRepl等によって実行時に、作成、削除、変更されうる。

The best way to set up a new namespace at the top of a Clojure source file is to use the ns macro. Clojureのソースファイルの冒頭で新しい名前空間を準備する最良の方法はnsマクロを使うことだ。By default this will create a new namespace that contains mappings for the classnames in java.lang plus clojure.lang.Compiler, and the functions in clojure.core. nsマクロが作る名前空間はデフォルトでjava.lang中のクラス名らとclojure.lang.Compilerへのマップを持ち、clojure.coreにある関数らについてもマップする。

At the Repl it's best to use in-ns, in which case the new namespace will contain mappings only for the classnames in java.lang. java.lang中のクラス名へのマップのみを持つ名前空間を作成するin-nsを使うのがReplでは最善だ。In order to access the names from the clojure.core namespace you must execute (clojure.core/refer 'clojure.core). clojure.coreにある名前らにアクセスするためには、(clojure.core/refer 'clojure.core)を実行しなければならない。The user namespace at the Repl has already done this. Replにおけるuser名前空間については、これは事前に実行されている。

The current namespace, *ns* can and should be set only with a call to in-ns or the ns macro, both of which create the namespace if it doesn't exist. 現在の名前空間*ns*は、in-nsかnsマクロを通してのみ設定されるべきだ。それらは両方とも、名前空間がまだなければ作成する。

Related functions 関連する関数

  • Creating and switching to a namespace 名前空間の作成ないし切り替え: in-ns ns create-ns
  • Adding to a namespace 名前空間への追加: alias def import intern refer
  • Finding what namespaces exist どんな名前空間が存在するか調べる: all-ns find-ns
  • Examining a namespace ある名前空間を調べる: ns-name ns-aliases ns-imports ns-interns ns-map ns-publics ns-refers
  • Getting a namespace from a symbol シンボルから名前空間を得る: resolve ns-resolve namespace
  • Removing things 削除する: ns-unalias ns-unmap remove-ns

原文: https://clojure.org/reference/namespaces