Stateful objects. References, mutation, cloning, etc.

Primary

blocking-reference?

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (blocking-reference? x)

Type signature: Predicate

Returns true if object x satisfies IBlockingReference protocol, false otherwise.

clone

Available since version 1.0 (view source)

Usage:
  • (clone x)

Type signature:
  • (Any) → Any

Returns a cloned object, or x, if it is not cloneable. May throw if objects forbids cloning.

deref

Available since version 1.0 (view source)

Usage:
  • (deref ref)

  • (deref ref timeout timeout-val)

Type signatures:
  • (IReference) → Any

  • (IBlockingReference ⨯ Any ⨯ Any) → Any

Returns the current state of ref. Concrete semantics differ based on object’s type. Types for which this function block return true for blocking-reference? predicate, and variant with timeout may be used for them.

ensure-io

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (ensure-io)

Type signature:
  • () → nil

Throws if not inside io! block. Returns nil. Is used to assert that the currently executed code is evaluated under the io! block.

See also: io!

io!

Available since version 1.0 (view source)

MACRO (io! & body)

If an io! block occurs in a transaction, throws an IllegalStateException, else runs body in an implicit do. If the first expression in body is a literal string, will use that as the exception message.

Some mutable functions, (e.g. reducing collections connected to live resource) must be run inside io! block. io! block is valid only in the current thread.

reference?

Available since version 1.0 (view source)

Usage:
  • (reference? x)

Type signature: Predicate

Returns true if object x satisfies IReference protocol, false otherwise.

Mutation

adjust!

Available since version 1.0 (view source)

Usage:
  • (adjust! ref key val)

  • (adjust! ref key val & keyvals)

Type signatures:
  • (IAdjustable ⨯ Any ⨯ Any) → IAdjustable

  • (IAdjustable ⨯ Any ⨯ Any ⨯ (Va Any)) → IAdjustable

Adjusts part of the ref state identified by a key to a given val and returns ref. Throws if key does not corresponds to any part of the state, or the particular part cannot be adjusted.

See also: adjustable?, reset!

adjustable?

Available since version 1.0 (view source)

Usage:
  • (adjustable? x)

Type signature: Predicate

Returns true if object x satisfies IAdjustable protocol, false otherwise.

See also: IAdjustable, adjust!, reset!

alter!

Available since version 1.0 (view source)

Usage:
  • (alter! ref f)

  • (alter! ref f x)

  • (alter! ref f x y)

  • (alter! ref f x y z)

  • (alter! ref f x y z & args)

Type signatures:
  • (IAtomic ⨯ Any) → Any

  • (IAtomic ⨯ Any ⨯ Any) → Any

  • (IAtomic ⨯ Any ⨯ Any ⨯ Any) → Any

  • (IAtomic ⨯ Any ⨯ Any ⨯ Any ⨯ Any) → Any

  • (IAtomic ⨯ Any ⨯ Any ⨯ Any ⨯ Any ⨯ (Va Any)) → Any

Atomically changes the referenced value to be: (apply f current-value args). f may be called multiple times, and thus should be free of side effects. Returns the new value.

atomic?

Available since version 1.0 (view source)

Usage:
  • (atomic? x)

Type signature: Predicate

Returns true if object x satisfies IAtomic protocol, false otherwise.

See also: IAtomic, mutable?, cas!

cas!

Available since version 1.0 (view source)

Usage:
  • (cas! ref oldval newval)

Type signature:
  • (IAtomic ⨯ Any ⨯ Any) → Boolean+

Atomically sets the value of the reference ref to newval if and only if the current value is identical to oldval. Returns true if set happened, otherwse returns false.

mutable?

Available since version 1.0 (view source)

Usage:
  • (mutable? x)

Type signature: Predicate

Returns true if object x satisfies IMutable protocol, false otherwise.

See also: IMutable, reset!

reset!

Available since version 1.0 (view source)

Usage:
  • (reset! ref val)

Type signature:
  • (IMutable ⨯ Any) → Any

Sets the referenced value to newval without regard for the current value. Returns the new value.

switch!

Available since version 1.0 (view source)

Usage:
  • (switch! ref newval)

Type signature:
  • (IAtomic ⨯ Any) → Any

Sets the value of atomic ref to newval and returns its previous value.

trade!

Available since version 1.0 (view source)

Usage:
  • (trade! ref f)

  • (trade! ref f x)

  • (trade! ref f x y)

  • (trade! ref f x y z)

  • (trade! ref f x y z & args)

Type signatures:
  • (IAtomic ⨯ Any) → Any

  • (IAtomic ⨯ Any ⨯ Any) → Any

  • (IAtomic ⨯ Any ⨯ Any ⨯ Any) → Any

  • (IAtomic ⨯ Any ⨯ Any ⨯ Any ⨯ Any) → Any

  • (IAtomic ⨯ Any ⨯ Any ⨯ Any ⨯ Any ⨯ (Va Any)) → Any

Atomically changes the referenced value to be: (apply f current-value args). f may be called multiple times, and thus should be free of side effects. Returns the old value.

Auxiliary

cancel!

Available since version 1.0 (view source)

Usage:
  • (cancel! x)

Type signature:
  • (ICancellable) → Boolean+

Attempts to cancel the object x, returning true if cancellation was successfull, otherwise returns false. Does not block.

cancellable?

Available since version 1.0 (view source)

Usage:
  • (cancellable? x)

Type signature: Predicate

Returns true if object x satisfies ICancellable protocol, false otherwise.

cancelled-aware?

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (cancelled-aware? x)

Type signature: Predicate

Returns true if object x satisfies ICancelledAware protocol, false otherwise.

cancelled?

Available since version 1.0 (view source)

Usage:
  • (cancelled? x)

Type signature:
  • (ICancelledAware) → Boolean+

Returns true if x is already cancelled, otherwise returns false.

ensure-open

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (ensure-open x)

Type signature:
  • (IOpenAware) → IOpenAware

Throws if x is not open. Returns x.

See also: open-aware?, open?

open-aware?

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (open-aware? x)

Type signature: Predicate

Returns true if object x satisfies IOpenAware protocol, false otherwise.

open?

Available since version 1.0 (view source)

Usage:
  • (open? x)

Type signature:
  • (IOpenAware) → Boolean+

Returns true if x is open, otherwise returns false. Open is taken in broader sense; if x is not open, it won’t perform most operations and is not 'operational'.

pending?

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (pending? x)

Type signature: Predicate

Returns true if object x satisfies IPending protocol, false otherwise.

See also: IPending, realized?

realized?

Available since version 1.0 (view source)

Usage:
  • (realized? x)

Type signature:
  • (IPending) → Boolean+

Returns true if the referenced value of x has been produced, otherwise returns false.

See also: pending?