Ref Type: Var

Overview

A var is a reference type which is isolated, synchronous, and autonomous:

  • isolated - each thread has access to its own item

  • synchronous - requested changes occur immediately

  • autonomous - changes are made to a single item

Example: Add 1 to this thread's version of bar, right now.

Vars provide a way to refer to a mutable storage location that can be dynamically rebound on a per-thread basis. See Transients for a more efficient alternative.

Clojure API

Note: "CC" links to the official Clojure documentation; "CD" links to ClojureDocs.

  • binding (CC, CD) - creates bindings for existing Vars

  • defn (CC, CD) - defines a public function as a Var

  • defn- (CC, CD) - defines a private function as a Var

  • set! (CC, CD) - sets a thread-local-bound Var

  • var (CC, CD) - creates and returns a Var

  • var-get (CC, CD) - gets the value in the Var object

  • var-set (CC, CD) - sets the value in the Var object

  • with-redefs (CC, CD) - temporarily redefines Vars for a body

  • with-redefs-fn (CC, CD) - temporarily redefines Vars for a function

To be continued...


This wiki page is maintained by Rich Morin, an independent consultant specializing in software design, development, and documentation. Please feel free to email comments, inquiries, suggestions, etc!

Topic revision: r8 - 27 Aug 2015, RichMorin
This site is powered by Foswiki Copyright © by the contributing authors. All material on this wiki is the property of the contributing authors.
Foswiki version v2.1.6, Release Foswiki-2.1.6, Plugin API version 2.4
Ideas, requests, problems regarding CFCL Wiki? Send us email