Vars , references with mutable root binding and thread local bindings that can be rebound dynamically.

Derefing a var gets its thread binding, or if it’s not bound in the current thread, gets its root binding. Var can have its root binding unbound.

Var

Available since version 1.0 (view source)

TYPE

A type for Vars.

See also: var?, def, declare

alter-root!

Available since version 1.0 (alias of clojure.core/alter-var-root)

not referred automatically

Usage:
  • (alter-root! v f & args)

Type signature:
  • (Var ⨯ AnyFn ⨯ (Va Any)) → Any

Atomically alters the root binding of var v by applying f to its current value plus any args. Mutates var.

See also: reset-root!, bound?

bindings

Available since version 1.0 (alias of clojure.core/get-thread-bindings)

not referred automatically

Usage:
  • (bindings)

Type signature:
  • () → {Var Any}

Gets a map with the Var/value pairs which is currently in effect for the current thread.

bound?

Available since version 1.0 (alias of clojure.core/bound?)

not referred automatically

Usage:
  • (bound? & vars)

Type signature:
  • ((Va Var)) → Boolean+

Returns true if all of the vars provided as arguments have any bound value, root or thread-local. Implies that deref’ing the provided vars will succeed. Returns true if no vars are provided.

declare

Available since version 1.0 (alias of clojure.core/declare)

MACRO (declare & names)

defs the supplied var names with no bindings, useful for making forward declarations.

See also: defonce, def, defalias

def

Available since version 1.0 (alias of clojure.bootstrap/def+)

MACRO (def name)  (def name def-arguments init)

Defines a var and returns it. The var definition process creates and interns or locates a global var with given name and a namespace of the value of the current namespace.

If initial value (last argument besides name) is supplied, it is evaluated, and the root binding of the var is set to the resulting value. If initial value is not supplied, the root binding of the var is unaffected.

def always applies to the root binding, even if the var is thread-bound at the point where def is called. name is an unqualified Symbol. Metadata from name is used as a metadata of the var. Rest of arguments (args) are parsed for docstring and attribute map, which are merged with vars metadata.

Throws an exception if name symbol is already in the namespace and not mapped to an interned var.

Use def+ instead of def in dunaj lite.

See also: defonce, declare, defalias, def+

def+

Available since version 1.0 (alias of clojure.bootstrap/def+)

MACRO (def+ name)  (def+ name def-arguments init)

Like def, but can be used in dunaj lite.

See also: defonce, declare, defalias, def

defalias

Available since version 1.0 (alias of clojure.bootstrap/defalias)

not referred automatically

MACRO (defalias name)  (defalias name def-arguments aliased)

Defines a var with the same root binding and metadata as the aliased var.

Aliased var name is optional and if not provided, it will be constructed as clojure.core/<_name_>.

See also: defonce, declare, def

defonce

Available since version 1.0 (alias of clojure.bootstrap/defonce)

MACRO (defonce name)  (defonce name doc-string? attr-map? init)

Defines a var, sets root binding if not yet set and returns the var.

See also: def, declare, defalias

find-var

Available since version 1.0 (alias of clojure.core/find-var)

not referred automatically

Usage:
  • (find-var sym)

Type signature:
  • (Symbol) → (Maybe Var)

Returns the global var named by the namespace-qualified symbol sym, or nil if there is no var with that name.

See also: var, def

letvar

Available since version 1.0 (alias of clojure.core/with-local-vars)

not referred automatically

MACRO (letvar bindings & body)

Executes the body in a context in which the symbols in bindings vec are bound to vars with per-thread bindings to the respective init-exprs. The symbols refer to the var objects themselves, and can be accessed with deref and reset!.

replace-macro!

Available since version 1.0 (view source)

not referred automatically

MACRO (replace-macro! dest source-var)

Replaces dest global var with source one, assuming source var contains a macro.

See also: replace-var

replace-var!

Available since version 1.0 (alias of clojure.bootstrap/replace-var!)

not referred automatically

MACRO (replace-var! dest)  (replace-var! dest source)

Replaces dest global var with source one, assuming source var does not contain a macro.

See also: replace-macro!

reset-root!

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (reset-root! var val)

Type signature:
  • (Var ⨯ Any) → Any

Resets root value of var to val. Returns new value. Mutates var.

thread-bound?

Available since version 1.0 (alias of clojure.core/thread-bound?)

not referred automatically

Usage:
  • (thread-bound? & vars)

Type signature:
  • ((Va Var)) → Boolean+

Returns true if all of the vars provided as arguments have thread-local bindings. Implies that set!'ing the provided vars will succeed. Returns true if no vars are provided.

var

Available since version 1.0 (view source)

MACRO (var symbol)

The symbol must resolve to a global var, and the Var object itself (not its value) is returned. The reader macro #'x expands to (var x).

See also: find-var, def

var?

Available since version 1.0 (view source)

Usage:
  • (var? x)

Type signature: Predicate

Returns true if object x is an instance of Var type, false otherwise.

See also: Var, def, declare

with-bindings

Available since version 1.0 (alias of clojure.core/with-bindings)

MACRO (with-bindings binding-map & body)

Takes a map of Var/value pairs. Installs for the given Vars the associated values as thread-local bindings. Then executes body. Pops the installed bindings after body was evaluated. Returns the value of body.

See also: bindings, with-roots, letvar

with-roots

Available since version 1.0 (view source)

not referred automatically

MACRO (with-roots binding-map & body)

Temporarily redefines Vars during the execution of body. Each val of binding-map will replaces the root value of its key which must be a Var. After the body is executed, the root values of all the Vars will be set back to their old values. These temporary changes will be visible in all threads. Useful for mocking out functions during testing.