Skip to content

clojure.core/intern

View this page on ClojureDocs

Type: function Added: Clojure 1.0 Examples: 4 Runnable: 0
([ns name] [ns name val])

Finds or creates a var named by the symbol name in the namespace ns (which can be a symbol or a namespace), setting its root binding to val if supplied. The namespace must exist. The var will adopt any metadata from the name symbol. Returns the var.

Examples

by Miles on . May have evaluation errors.
by jungwookim on . May have evaluation errors.
by jungwookim on . May have evaluation errors.
by tomdl89 on . May have evaluation errors.

Note by phreed

"The Namespace system maintains global maps of symbols to Var objects (see Namespaces). If a def expression does not find an interned entry in the current namespace for the symbol being def-ed, it creates one, otherwise it uses the existing Var. This find-or-create process is called interning. This means that, unless they have been unmap-ed, Var objects are stable references and need not be looked up every time. It also means that namespaces constitute a global environment in which, as described in Evaluation, the compiler attempts to resolve all free symbols as Vars.

"The var special form or the #' reader macro (see Reader) can be used to get an interned Var object instead of its current value."

-- [https://clojure.org/reference/vars]

See also


Content from the matching ClojureDocs page, with authors credited on each contribution.