SUPPORT THE WORK

GetWiki

Clojure

ARTICLE SUBJECTS
aesthetics  →
being  →
complexity  →
database  →
enterprise  →
ethics  →
fiction  →
history  →
internet  →
knowledge  →
language  →
licensing  →
linux  →
logic  →
method  →
news  →
perception  →
philosophy  →
policy  →
purpose  →
religion  →
science  →
sociology  →
software  →
truth  →
unix  →
wiki  →
ARTICLE TYPES
essay  →
feed  →
help  →
system  →
wiki  →
ARTICLE ORIGINS
critical  →
discussion  →
forked  →
imported  →
original  →
Clojure
[ temporary import ]
please note:
- the content below is remote from Wikipedia
- it has been imported raw for GetWiki
{{short description|A modern, dynamic, and functional Lisp on JVM}}{{Distinguish|Clozure CL|Google Closure Tools|Closure (computer programming)}}









|| 1.0| 1.1| 1.2| 1.3| 1.4| 1.5| 1.5.1| 1.6| 1.7| 1.8| 1.9| 1.10
factoids
name Clojure| logo = Clojure logo.svg



multi-paradigm programming language>multi-paradigm:{{flatlist|
  • concurrentWEB,weblink Clojure.org, Concurrent Programming, 2019-07-07, WEB,weblink GitHub.com, core.async, Hickey, Rich, contributors, 2019-07-07,
  • functionalWEB,weblink Clojure.org, Functional Programming, 2019-07-07,
  • logicWEB,weblink GitHub.com, core.logic, Nolen, David, Hickey, Rich, contributors, 2019-07-07,
  • macroWEB,weblink Clojure.org, Macros, 2019-07-07,
  • pipelineWEB,weblink Clojure.org, Threading Macros Guide, Esterhazy, Paulus, 2019-07-07,
  • }}
    {edih}| implementations =| dialects = }}
    • Elixir
    • Hy
    • LFE
    • PixieWEB,weblink PixieLang.org, Pixie, Baldridge, Timothy, 2019-07-07,
    • RhineWEB,weblink GitHub.org, Rhine, Ramachandra, Ramkumar, 2019-07-07,
    }}
    }}| license = Eclipse Public Licenseweblink}}
    • .clj
    • .cljs
    • .cljc
    • .edn
    }}| wikibooks = Clojure Programming}}Clojure ({{IPAc-en|ˈ|k|l|oʊ|ʒ|ər}}, like closure)WEB,weblink Google.com, meaning and pronunciation of Clojure, Hickey, Rich, 2009-01-05, is a modern, dynamic, and functional dialect of the Lisp programming language on the Java platform.WEB,weblink InfoWorld.com, Clojure inventor Hickey now aims for Android, Krill, Paul, 2012-03-22, WEB,weblink Clojure, Clojure.org, 2019-07-07, Like other Lisps, Clojure treats code as data and has a Lisp macro system.WEB,weblink Clojure.org, Differences with other Lisps, 2019-07-07, The current development process is community-driven,WEB,weblink Clojure.org, Development, 2019-07-07, overseen by Rich Hickey as its benevolent dictator for life (BDFL).WEB,weblink GitHub.com, Open Source is Not About You, Hickey, Rich, 2018-11-26, Clojure advocates immutability and immutable data structures and encourages programmers to be explicit about managing identity and its states.WEB,weblink Clojure.org, Values and Change: Clojure’s approach to Identity and State, 2019-07-07, This focus on programming with immutable values and explicit progression-of-time constructs is intended to facilitate developing more robust, especially concurrent, programs.WEB,weblink Rationale, Hickey, Rich, Clojure.org, 2019-07-07, WEB,weblink MSDN.com, Expert to Expert: Rich Hickey and Brian Beckman – Inside Clojure, Torre, Charles, 2009-10-06, While its type system is entirely dynamic, recent efforts have also sought the implementation of gradual typing.WEB,weblink GitHub.com, core.typed, 2019-07-07,
    Commercial support for Clojure is provided by Cognitect.WEB,weblink Cognitect.com, Investing in A Better Way, 2019-07-07, Annual Clojure conferences are organized every year across the globe, the most famous of them being Clojure/conj.WEB,weblink Clojure-Conj.org, Clojure/conj, 2019-07-07,

    History and development process

    (File:Rich Hickey.jpg|thumb|Rich Hickey, creator of Clojure)Rich Hickey is the creator of the Clojure language. Before Clojure, he developed dotLisp, a similar project based on the .NET platform,WEB,weblink Google.com, [ANN] dotLisp – a Lisp dialect for .Net, Hickey, Rich, 2002-10-16, and three earlier attempts to provide interoperability between Lisp and Java: a Java foreign language interface for Common Lisp (jfli),WEB,weblink SourceForge.net, jfli, Hickey, Rich, 2013-04-15, A Foreign Object Interface for Lisp (FOIL),WEB,weblink SourceForge.net, foil - Foreign Object Interface for Lisp, Hickey, Rich, 2013-04-03, and a Lisp-friendly interface to Java Servlets (Lisplets).WEB,weblink SourceForge.net, Lisplets, Hickey, Rich, 2013-03-07, Hickey spent about 2½ years working on Clojure before releasing it publicly, much of that time working exclusively on Clojure with no outside funding. At the end of this time, Hickey sent an email announcing the language to some friends in the Common Lisp community.The development process is community-driven and is managed at the Clojure JIRA project page WEB,weblink Atlassian.net, Clojure, 2019-07-07, where issues may be filed. General development discussion occurs at the Clojure Google Group.WEB,weblink Google.com, Clojure, 2019-07-07, Anyone can submit issues and ideas, but to contribute patches, one must sign the Clojure Contributor agreement.WEB,weblink Clojure.org, Contributor Agreement, 2019-07-07, JIRA issues are processed by a team of screeners and finally Rich Hickey approves the changes.WEB,weblink Clojure.org, Workflow, 2019-07-07,

    Design philosophy

    Rich Hickey developed Clojure because he wanted a modern Lisp for functional programming, symbiotic with the established Java platform, and designed for concurrency.WEB,weblink LinuxJournal.com, Economy Size Geek – Interview with Rich Hickey, Creator of Clojure, Elmendorf, Dirk, 2010-04-01, Clojure's approach to state is characterized by the concept of identities, which are represented as a series of immutable states over time. Since states are immutable values, any number of workers can operate on them in parallel, and concurrency becomes a question of managing changes from one state to another. For this purpose, Clojure provides several mutable reference types, each having well-defined semantics for the transition between states.

    Language Overview{| class"wikitable"

    ! Version! Release date! Major features/improvements
    TITLE=CLOJURE IS TWO! FIRST=RICH, 2007-10-16, |Initial public release
    TITLE=CLOJURE 1.0 FIRST=RICH, 2009-05-04, |First stable release
    TITLE=CLOJURE 1.1 RELEASE FIRST=RICH, 2009-12-31, |Futures
    TITLE=CLOJURE 1.2 RELEASE FIRST=RICH, 2010-08-19, |Protocols
    TITLE=[ANN] CLOJURE 1.3 RELEASED FIRST=CHRISTOPHER, 2011-09-23, |Enhanced primitive support
    TITLE=[ANN] CLOJURE 1.4 RELEASED FIRST=ALAN, 2012-04-17, |Reader literals
    TITLE=ANN: CLOJURE 1.5 FIRST=STUART, 2013-03-01, |Reducers
    TITLE=CLOJURE 1.5.1 FIRST=STUART, 2013-03-10, | Fixing a memory leak
    TITLE=[ANN] CLOJURE 1.6 FIRST=ALEX, 2014-03-25, |Java API, improved hashing algorithms
    TITLE=CLOJURE 1.7 IS NOW AVAILABLE FIRST=ALEX, 2015-06-30, |Transducers, reader conditionals
    TITLE=CLOJURE 1.8 IS NOW AVAILABLE FIRST=ALEX, 2016-01-19, |Additional string functions, direct linking, socket server
    TITLE=CLOJURE 1.9 IS NOW AVAILABLE FIRST=ALEX, 2017-12-08, |Integration with spec, command-line tools
    TITLE=CLOJURE 1.10 RELEASE FIRST=ALEX, 2018-12-17, |Improved error reporting, Java compatibility
    c |1.10.1}}TITLE=CLOJURE 1.10.1 RELEASE FIRST=ALEX, 2019-06-06, |Working around a Java performance regression and improving error reporting from clojure.main
    {{Versionshow=000100}}
    Clojure runs on the Java platform and as a result, integrates with Java and fully supports calling Java code from Clojure,WEB,weblink Clojure.org, Hosted on the JVM, 2019-07-07, and Clojure code can be called from Java also.WEB,weblink Java Interop, Clojure.org, 2019-07-07, The community uses Leiningen for project automation, providing support for Maven integration. Leiningen handles project package management and dependencies and is configured using Clojure syntax.WEB,weblink Leiningen.org, Leiningen, Hagelberg, Phil, contributors, 2019-07-07, Like most other Lisps, Clojure's syntax is built on S-expressions that are first parsed into data structures by a reader before being compiled.WEB,weblink Clojure.org, The Reader, 2019-07-07, Clojure's reader supports literal syntax for maps, sets and vectors in addition to lists, and these are compiled to the mentioned structures directly. Clojure is a Lisp-1 and is not intended to be code-compatible with other dialects of Lisp, since it uses its own set of data structures incompatible with other Lisps.As a Lisp dialect, Clojure supports functions as first-class objects, a read–eval–print loop (REPL), and a macro system. Clojure's Lisp macro system is very similar to that in Common Lisp with the exception that Clojure's version of the backquote (termed "syntax quote") qualifies symbols with their namespace. This helps prevent unintended name capture, as binding to namespace-qualified names is forbidden. It is possible to force a capturing macro expansion, but it must be done explicitly. Clojure does not allow user-defined reader macros, but the reader supports a more constrained form of syntactic extension.WEB,weblink GitHub.com, edn, Hickey, Rich, 2019-07-07, Clojure supports multimethodsWEB,weblink Clojure.org, Multimethods and Hierarchies, 2019-07-07, and for interface-like abstractions has a protocolWEB,weblink Clojure.org, Protocols, 2019-07-07, based polymorphism and data type system using records,WEB,weblink Clojure.org, Datatypes: deftype, defrecord and reify, 2019-07-07, providing high-performance and dynamic polymorphism designed to avoid the expression problem.Clojure has support for lazy sequences and encourages the principle of immutability and persistent data structures. As a functional language, emphasis is placed on recursion and higher-order functions instead of side-effect-based looping. Automatic tail call optimization is not supported as the JVM does not support it natively;WEB,weblink Stewardship: the Sobering Parts, YouTube.com, Goetz, Brian, 2014-11-20, WEB,weblink Oracle.com, tail calls in the VM, Rose, John, 2007-07-12, WEB,weblink Java.net, Some languages need to be able to perform tail calls, Rose, John, 2009-02-11, it is possible to do so explicitly by using the recur keyword.WEB,weblink Clojure.org, Special Forms, 2019-07-07, For parallel and concurrent programming Clojure provides software transactional memory,WEB,weblink Clojure.org, Refs and Transactions, 2019-07-07, a reactive agent system, and channel-based concurrent programming.WEB,weblink Clojure.org, Clojure core.async Channels, Hickey, Rich, 2013-06-28, Clojure 1.7 introduced reader conditionals by allowing the embedding of Clojure and ClojureScript code in the same namespace. Transducers were added as a method for composing transformations. Transducers enable higher-order functions such as map and fold to generalize over any source of input data. While traditionally these functions operate on sequences, transducers allow them to work on channels and let the user define their own models for transduction.WEB,weblink YouTube.com, Transducers, Hickey, Rich, 2014-09-17, WEB,weblink Cognitect.com, Transducers are Coming, Hickey, Rich, 2014-08-06, WEB,weblink YouTube.com, Inside Transducers, Hickey, Rich, 2014-11-20,

    Platforms

    The primary platform of Clojure is Java, but other target implementations exist. The most notable of these are ClojureScript,WEB,weblink ClojureScript.org, ClojureScript, 2019-07-06, which compiles to ECMAScript 3,WEB,weblink ClojureScript.org, ClojureScript – FAQ (for JavaScript developers), 2018-02-04, and ClojureCLR,WEB,weblink GitHub.com, ClojureCLR, 2012-06-28, a full port on the .NET platform, interoperable with its ecosystem. A survey of the Clojure community with 1,060 respondents conducted in 2013WEB,weblink CEmerick.com, Results of the 2013 State of Clojure & ClojureScript survey, Emerick, Chas, 2013-11-18, found that 47% of respondents used both Clojure and ClojureScript when working with Clojure. In 2014 this number had increased to 55%,WEB,weblink WuFoo.com, State of Clojure 2014 Survey Results, 2015-09-17, in 2015, based on 2,445 respondents, to 66%.WEB,weblink Cognitect.com, State of Clojure 2015 Survey Results, Gehtland, Justin, 2016-01-28, Popular ClojureScript projects include implementations of the React library such as ReagentWEB,weblink GitHub.io, Reagent, 2019-07-06, , re-frame,WEB,weblink GitHub.com, re-frame, 2019-07-06, Rum,WEB,weblink GitHub.com, Rum, Prokopov, Nikita, 2019-07-06, and Om.WEB,weblink GitHub.com, Om, Nolen, David, 2019-07-06, WEB,weblink InfoQ.com, Om: Enhancing Facebook's React with Immutability, Coupland, Tom, 2014-01-17,

    Popularity

    With the continued interest in functional programming, Clojure's adoption by the software developers on the Java platform has kept increasing. The language has also been either preferred or recommended by renowned software development veterans such as James Gosling,WEB,weblink YouTube.com, James Gostling meetup with London Java Community, 2016-10-11, Paul Graham,WEB,weblink Twitter.com, Paul Graham on Twitter, Graham, Paul, 2016-05-06, and Robert C. Martin (colloquially known as "Uncle Bob".)WEB,weblink Twitter.com, Unble Bob Martin on Twitter, Martin, Robert, 2018-11-29, WEB,weblink CleanCoders.com, Introduction To Functional Programming, Martin, Robert, 2018-08-01, WEB,weblink CleanCoder.com, Pragmatic Functional Programming, Martin, Robert, 2017-07-11, In the "JVM Ecsosystem Report 2018" (which was claimed to be "the largest survey ever of Java developers"), prepared in collaboration by Snyk and Java Magazine, Clojure was ranked the 2nd most used programming language (behind Java) for "main applications".WEB,weblink Snyk.io, JVM Ecosystem Report 2018, Maple, Simon, Binstock, Andrew, 2018-10-17, Clojure is used in industry by firmsWEB,weblink Clojure.org, Success Stories, 2018-10-27, such as Apple,WEB,weblink Twitter.com, Roman Liutikov on Twitter, Liutikov, Roman, 2017-12-17, WEB,weblink Apple.com, Jobs at Apple, 2019-07-06, Atlassian,WEB,weblink YouTube.com, Realtime Collaboration with Clojure, Borges, Leonardo, 2015-07-07, Funding Circle,WEB,weblink JUXT.pro, Clojure in London: Funding Circle – Lending some Clojure, Pither, Jon, 2016-10-04, Netflix,WEB,weblink TheNewStack.io, The New Stack Makers: Adrian Cockcroft on Sun, Netflix, Clojure, Go, Docker and More, Williams, Alex, 2014-08-03, Puppet,WEB,weblink PuppetLabs.com, A New Era of Application Services at Puppet Labs, Price, Chris, 2014-04-11, and WalmartWEB,weblink Cognitect.com, Walmart Runs Clojure at Scale, Phillips, Marc, 2015-07-14, as well as government agencies such as NASAWEB,weblink GitHub.com, Common-Metadata-Repository, 2019-07-06, . It has also been used for creative computing, including visual art, music, games, and poetry.WEB,weblink OReilly.com, Creative computing with Clojure, Meier, Carin, 2015-05-06, ThoughtWorks, while assessing functional programming languages for their Technology Radar,WEB,weblink ThoughtWorks.com, Frequently Asked Questions - Technology Radar - ThoughtWorks, 2019-02-10, expressed their favor toward Clojure as "a simple, elegant implementation of Lisp on the JVM" in 2010 and promoted its status to "ADOPT" in 2012.WEB,weblink ThoughtWorks.com, Clojure - Technology Radar - ThoughtWorks, 2019-02-10, A growing number of unofficial and experimental implementations for other platforms testify to the popularity of the language:
    • CljPerl,WEB,weblink MetaCPAN.org, A Lisp on Perl, Hu, Wei, 2019-07-06, Clojure atop Perl
    • Clojerl,WEB,weblink GitHub.com, Clojerl, Facorro, Juan, 2019-07-06, Clojure on BEAM, the Erlang virtual machine
    • clojure-py,WEB,weblink GitHub.com, clojure-py, Baldridge, Timothy, 2019-07-06, Clojure in pure Python
    • Ferret,WEB,weblink Ferret-Lang.org, Ferret, Akkaya, Nurullah, 2019-07-06, compiles to self-contained C++11 that can run on microcontrollers
    • Joker,WEB,weblink Joker-Lang.org, Joker, Bataev, Roman, 2019-07-06, an interpreter and linter written in Go
    • Las3r,WEB,weblink GitHub.com, Laz3r, Cannon, Aemon, 2019-07-06, a subset of Clojure that runs on the ActionScript Virtual Machine (the Adobe Flash Player platform)
    • Pixie,WEB,weblink PixieLang.org, Pixie, Baldridge, Timothy, 2019-07-06, Clojure-inspired Lisp dialect written in RPython
    • Rouge,WEB,weblink GitHub.com, Rouge, Connor, Ashe, 2019-07-06, Clojure atop YARV in Ruby

    Tools

    Tooling for Clojure development has seen significant improvement over the years. The following is a list of the most popular IDEs/editors with their plug-ins that combined provide excellent support for Clojure development:WEB,weblink Clojure.org, "State of Clojure 2019" Results, Miller, Alex, 2019-02-04,
    • Atom, with ChlorineWEB,weblink Atom.io, Chlorine: Socket REPL Client for Clojure and ClojureScript, Szabo, Maurício, 2019-07-05,
    • Emacs, with CIDERWEB,weblink CIDER.mx, CIDER: The Clojure Interactive Development Environment that Rocks, Batsov, Bozhidar, contributors, 2019-07-05,
    • IntelliJ IDEA, with Clojure-KitWEB,weblink JetBrains.com, Clojure-Kit: Clojure and ClojureScript plugin for IntelliJ-based tools, Shrago, Greg, 2019-07-05, or CursiveWEB,weblink JetBrains.com, Cursive: Provides full Clojure and ClojureScript language support, Fleming, Colin, 2019-07-05, (a free, non-commercial license is available)
    • Light Table
    • Vim, with fireplace.vimWEB,weblink VIM.org, fireplace.vim: Clojure REPL Support, Pope, Tim, 2019-07-05, WEB,weblink JUXT.pro, Clojure and Vim: An overview – It's very possible, Monroe, Dominic, 2016-12-13,
    • Visual Studio Code, with CalvaWEB,weblink VisualStudio.com, Calva: Clojure & ClojureScript Interactive Programming, Strömberg, Peter, 2019-07-05,
    In addition to the tools provided by the community, the official Clojure CLI toolsWEB,weblink Clojure.org, Deps and CLI Guide, Miller, Alex, 2019-07-08, have also become available on GNU/Linux, macOS, and Windows since Clojure 1.9.WEB,weblink Cognitect.com, Clojure 1.9, Miller, Alex, 2017-12-08,

    Features by Example

    The following examples can be run in a Clojure REPL such as one started with the Clojure CLI tools or an online REPL such as one available on REPL.it.WEB,weblink REPL.it, Online Clojure REPL, 2019-07-08,

    Simplicity

    Because of the strong emphasis on simplicity, typical Clojure programs consist of mostly functions and simple data structures (i.e., lists, vectors, maps, and sets):
    a typical entry point of a Clojure program
    (defn -main ; function name
    [& args] ; parameter vector (`-main` is a variadic function)
    (println "Hello, World!")) ; function body

    Programming at REPL

    Like other Lisps, one of the iconic features of Clojure is interactive programming at the REPL.WEB,weblink Clojure.org, Programming at the REPL: Introduction, 2018-12-04, Note that, in the following examples, ;; starts a line comment and ;; => indicates output:
    define a var
    (def a 42)
    => #'user/a
    call a function named `+`
    (+ a 8)
    => 50
    call a function named `even?`
    (even? a)
    => true
    define a function that returns the remainder of `n` when divided by 10
    (defn foo [n] (rem n 10))
    => #'user/foo
    call the function
    (foo a)
    => 2
    print the docstring of `rem`
    (doc rem)
    =>
    ---------------------
    clojure.core/rem([num div])
    remainder of dividing numerator by denominator.


    print the source of `rem`
    (source rem)
    =>
    (defn rem
    "remainder of dividing numerator by denominator."
    {:added "1.0"
    :static true
    :inline (fn [x y] `(. clojure.lang.Numbers (remainder ~x ~y)))}
    [num div]
    (. clojure.lang.Numbers (remainder num div)))

    Names at runtime

    Unlike other runtime environments where names get compiled away, Clojure's runtime environment is easily introspectable using normal Clojure data structures:
    define a var
    (def a 42)
    => #'user/a
    get a map of all public vars interned in the `user` namespace
    (ns-publics 'user)
    => {a #'user/a}
    reference the var via `#'` (reader macro) and
    its associated, namespace-qualified symbol `user/a`
    1. 'user/a


    => #'user/a
    de-reference (get the value of) the var
    (deref #'user/a)
    => 42
    define a function (with a docstring) that
    returns the remainder of `n` when divided by 10
    (defn foo "returns `(rem n 10)`" [n] (rem n 10))
    => #'user/foo
    get the metadata of the var `#'user/foo`
    (meta #'user/foo)
    =>
    {:arglists ([n]),
    :doc "returns `(rem n 10)`",
    :line 1,
    :column 1,
    :file "user.clj",
    :name foo,
    :ns #namespace[user]}

    Code as data (homoiconicity)

    Similar to other Lisps, Clojure is homoiconic (also known as code as data). In the example below, we can see how easy it is to write code that modifies code itself:
    call a function (code)
    (+ 1 1)
    => 2
    quote the function call
    (turning code into data, which is a list of symbols)
    (quote (+ 1 1))
    => (+ 1 1)
    get the first element on the list
    (operating on code as data)
    (first (quote (+ 1 1)))
    => +
    get the last element on the list
    (operating on code as data)
    (last (quote (+ 1 1)))
    => 1
    get a new list by replacing the symbols on the original list
    (manipulating code as data)
    (map (fn [form]
    (case form
    1 'one
    + 'plus))
    (quote (+ 1 1)))


    => (plus one one)

    Expressive operators for data transformation

    The threading macros (->, ->>, and friends) can syntactically express the abstraction of piping a collection of data through a series of transformations:(->> (range 10)
    (map inc)
    (filter even?))


    => (2 4 6 8 10)
    This can also be achieved more efficiently using transducers:(sequence (comp (map inc)
    (filter even?))
    (range 10))


    => (2 4 6 8 10)

    Thread-safe management of identity and state

    A thread-safe generator of unique serial numbers (though, like many other Lisp dialects, Clojure has a built-in gensym function that it uses internally):(def i (atom 0))(defn generate-unique-id
    "Returns a distinct numeric ID for each call."
    []
    (swap! i inc))

    Macros

    An anonymous subclass of java.io.Writer that doesn't write to anything, and a macro using it to silence all prints within it:(def bit-bucket-writer
    (proxy [java.io.Writer] []
    (write [buf] nil)
    (close [] nil)
    (flush [] nil)))
    (defmacro noprint
    "Evaluates the given `forms` with all printing to `*out*` silenced."
    [& forms]
    `(binding [*out* bit-bucket-writer]
    ~@forms))
    (noprint
    (println "Hello, nobody!"))


    => nil

    Language interoperability with Java

    Clojure was created from ground up to embrace its host platforms as one of its design goals thus provides excellent language interoperability with Java:
    call an instance method
    (.toUpperCase "apple")
    => "APPLE"
    call a static method
    (System/getProperty "java.vm.version")
    => "12+33"
    create an instance of `java.util.HashMap` and
    add some entries
    (doto (java.util.HashMap.)
    (.put "apple" 1)
    (.put "banana" 2))


    => {"banana" 2, "apple" 1}
    create an instance of `java.util.ArrayList` and
    increment its elements with `clojure.core/map`
    (def al (doto (java.util.ArrayList.)
    (.add 1)
    (.add 2)
    (.add 3)))
    (map inc al)
    => (2 3 4)
    show a message dialog using Java Swing
    (javax.swing.JOptionPane/showMessageDialog
    nil
    "Hello, World!")


    => nil

    Software transactional memory

    10 threads manipulating one shared data structure, which consists of 100 vectors each one containing 10 (initially sequential) unique numbers. Each thread then repeatedly selects two random positions in two random vectors and swaps them. All changes to the vectors occur in transactions by making use of Clojure's software transactional memory system:(defn run
    [nvecs nitems nthreads niters]
    (let [vec-refs
    (->> (* nvecs nitems)
    (range)
    (into [] (comp (partition-all nitems)
    (map vec)
    (map ref))))


    swap
    #(let [v1 (rand-int nvecs)
    v2 (rand-int nvecs)
    i1 (rand-int nitems)
    i2 (rand-int nitems)]
    (dosync
    (let [tmp (nth @(vec-refs v1) i1)]
    (alter (vec-refs v1) assoc i1 (nth @(vec-refs v2) i2))
    (alter (vec-refs v2) assoc i2 tmp))))


    report
    #(->> vec-refs
    (into [] (comp (map deref)
    (map (fn [v] (prn v) v))
    cat
    (distinct)))
    (count)
    (println "Distinct:"))]


    (report)


    (->> #(dotimes [_ niters] (swap))
    (repeat nthreads)
    (apply pcalls)
    (dorun))


    (report)))
    (run 100 10 10 100000)
    =>
    [0 1 2 3 4 5 6 7 8 9][10 11 12 13 14 15 16 17 18 19]
    ...
    [990 991 992 993 994 995 996 997 998 999]Distinct: 1000[382 318 466 963 619 22 21 273 45 596][808 639 804 471 394 904 952 75 289 778]
    ...
    [484 216 622 139 651 592 379 228 242 355]Distinct: 1000nil

    See also

    References

    {{Reflist|2}}

    Further reading

    • {{citation| first1 = Russ| last1 = Olsen| year = 2018| title = Getting Clojure| publisher = Pragmatic Bookshelf| edition = 1st| isbn = 978-1-68050-300-5| url =weblink
    }}
    • {{citation| first1 = Alex| last1 = Miller| first2 = Stuart| last2 = Halloway| first3 = Aaron| last3 = Bedra| year = 2018| title = Programming Clojure| publisher = Pragmatic Bookshelf| edition = 3rd| isbn = 978-1-68050-246-6| url =weblink
    }}
    • {{citation| first1 = Dmitri| last1 = Sotnikov| year = 2016| title = Web Development with Clojure| publisher = Pragmatic Bookshelf| edition = 2nd| isbn = 978-1-68050-082-0| url =weblink
    }}
    • {hide}citation| first1 = Amit| last1 = Rathore| first2 = Francis| last2 = Avila| year = 2015| title = Clojure in ActionManning_Publications>Manning| edition = 2nd| isbn = 978-1-61729-152-4
    {edih}
    • {{citation| first1 = Daniel| last1 = Higginbotham| year = 2015| title = Clojure for the Brave and True| publisher = No Starch Press| edition = 1st| isbn = 978-1-59327-591-4| url =weblink
    }}
    • {{citation| first1 = Julian| last1 = Gamble| year = 2015| title = Clojure Recipes| publisher = Pearson Publishing| edition = 1st| isbn = 978-0-32192-773-6| url =weblink
    }}
    • {{citation| first1 = Ben| last1 = Vandgrift| first2 = Alex| last2 = Miller| year = 2015| title = Clojure Applied| publisher = Pragmatic Bookshelf| edition = 1st| isbn = 978-1-68050-074-5| url =weblink
    }}
    • {{citation| first1 = Eric| last1 = Rochester| year = 2015| title = Clojure Data Analysis Cookbook| publisher = Packt Publishing| edition = 2nd| isbn = 978-1-78439-029-7| url =weblink
    }}
    • {{citation| first1 = Michael| last1 = Fogus| first2 = Chris| last2 = Houser| year = 2014| title = The Joy of Clojure
    Manning_Publications>Manning| edition = 2nd| isbn = 1-617291-41-2| url =weblink}}
    • {{citation| first1 = Eric| last1 = Rochester| year = 2014| title = Mastering Clojure Data Analysis| publisher = Packt Publishing| edition = 1st| isbn = 978-1-78328-413-9| url =weblink
    }}
    • {{citation| first1 = Chas| last1 = Emerick| first2 = Brian| last2 = Carper| first3 = Christophe| last3 = Grand| date = April 19, 2012| title = Clojure Programming| publisher = O'Reilly Media| edition = 1st| isbn = 1-4493-9470-1| url =weblink
    }}
    • {{citation| first1 = Luke| last1 = VanderHart| first2 = Stuart| last2 = Sierra| date = June 7, 2010| title = Practical Clojure| publisher = Apress| edition = 1st| isbn = 978-1-4302-7231-1| url =weblink
    }}

    External links

    {{Official website}}{{Lisp programming language}}{{Lisp}}{{Java (Sun)}}{{Authority control}}

    - content above as imported from Wikipedia
    - "Clojure" does not exist on GetWiki (yet)
    - time: 1:11pm EDT - Sun, Aug 18 2019
    [ this remote article is provided by Wikipedia ]
    LATEST EDITS [ see all ]
    GETWIKI 09 JUL 2019
    Eastern Philosophy
    History of Philosophy
    GETWIKI 09 MAY 2016
    GETWIKI 18 OCT 2015
    M.R.M. Parrott
    Biographies
    GETWIKI 20 AUG 2014
    GETWIKI 19 AUG 2014
    CONNECT