Refs, a transactional references that use software transactional memory (STM) for safe shared use of mutable references.

IRef

Available since version 1.0 (view source)

PROTOCOL with methods -ensure, -commute, -alter, -reset, -history-count

An abstract type protocol for Refs.

See also: ref?, ref, dosync

-ensure

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (-ensure this)

Type signature:
  • (Any) → Any

Must be called in a transaction. Protects this from modification by other transactions. Returns the in-transaction-value of this.

See also: IRef

-commute

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (-commute this f args)

Type signature:
  • (Any ⨯ AnyFn ⨯ [Any]) → Any

Must be called in a transaction. Sets the in-transaction-value of this to: (apply f in-transaction-value-of-ref args) and returns the in-transaction-value of this. At the commit point of the transaction, sets the value of this to be: (apply f most-recently-committed-value-of-ref args)

See also: IRef

-alter

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (-alter this f args)

Type signature:
  • (Any ⨯ AnyFn ⨯ [Any]) → Any

Must be called in a transaction. Sets the in-transaction-value of this to: (apply f in-transaction-value-of-ref args) and returns the in-transaction-value of this.

See also: IRef

-reset

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (-reset this val)

Type signature:
  • (Any ⨯ Any) → Any

Must be called in a transaction. Sets the value of this. Returns val.

See also: IRef

-history-count

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (-history-count this)

Type signature:
  • (Any) → Integer+

Returns the history count of this ref.

See also: IRef