dunaj.state.var API
version 0.7.0
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
Extends: ICloneable
, IInvocable
, IMeta
, IMult
, IMutable
, IMutableMeta
, INamed
, INamespaced
, IReference
, IValidator
A type for Vars.
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.
See also: with-bindings
, with-roots
, letvar
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.
See also: thread-bound
, alter-root!
, reset-root!
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.
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.
|
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.
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_>
.
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.
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.
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!
.
See also: with-bindings
, with-roots
, bindings
, def
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
.
See also: alter-root!
, bound?
, dunaj.state/reset!
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.
See also: bound?
, dunaj.state/reset!
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).
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.
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.
See also: with-bindings
, bindings
, letvar