Clojure

from Wikipedia, the free encyclopedia
Clojure
Clojure logo
Lisp dialect
Basic data
Paradigms : Functional programming language
Publishing year: 2007
Developer: Rich Hickey
Current  version : 1.10.1   (June 6, 2019)
Typing : dynamic , strong
Influenced by: Lisp , Prolog , ML , Erlang , Haskell , Java
Operating system : Windows , Linux , macOS , Solaris , FreeBSD
License : Eclipse Public License
https://clojure.org/

Clojure [ ˈkləʊʒə (r) ] is a modern Lisp dialect that supports interactive development. The language promotes a functional style that greatly simplifies concurrent programming. Clojure runs in the Java Virtual Machine and is tightly integrated with the Java Runtime . A JavaScript implementation called ClojureScript and a CLR implementation also exist. The macro system is comparable to that of other Lisp environments.

Clojure projects are often realized with the help of Leiningen .

Examples

Full Hello World Programs :

textually in Lisp style:

(println "Hallo Welt!")

graphically using the Java library Swing :

(javax.swing.JOptionPane/showMessageDialog nil "Hallo Welt!")

The factorial function as an example of recursion in Clojure:

(defn factorial [n]
  "tail recursive version of n!"
  (loop [cur n, acc 1]
    (if (<= cur 1)
      acc
      (recur (dec cur) (*' cur acc)))))

The factorial function by using higher order functions:

(defn fac [n]
  (reduce *' (range 1 (inc n))))

Features of Clojure

  • Functional language with a Lisp syntax.
  • Dynamic, interactive development in the REPL ( read-eval-print loop ).
  • In addition to the list that is classic in Lisp , the syntax supports vectors, associative arrays and sets.
  • The abstraction of the sequence allows all these data structures to be used uniformly with the same functions. Consequences are typically evaluated with a delay ( lazy ).
  • All data structures are values ​​( immutable ).
  • Stateful data are implemented in Clojure using special types ( atoms and refs ). The competitive access to variables with changeable values ​​is synchronized by means of STM ( software transactional memory ) through the language's runtime system. The concepts correspond to the multi-version Concurrency Control as used in database management systems (exactly as in Oracle ).
  • Clojure is compiled to Java bytecode and executed in the Java Virtual Machine . This makes it possible to use any Java library in Clojure, and for a great many of these there are (often narrow) wrapper libraries in Clojure.
  • In addition to Clojure, there is ClojureScript , a language that shares concept and syntax with Clojure. Clojurescript is compiled to JavaScript .

Homonicity

As a Lisp dialect, the principle of code as data or homoiconicity plays an important role. The Clojure macro system is based on this property and thus allows metaprogramming . Specifically, Clojure can benefit from this by making properties that are firmly integrated in other programming languages ​​available as libraries. Pattern matching and a type system are examples here .

IDE support

  • Light Table is an interactive IDE with Clojure support.
  • The Cursive plug-in is available for IntelliJ IDEA .
  • Counterclockwise is available for Eclipse .
  • A ClojureCLR extension for Visual Studio is vsClojure.
  • Clojure-Mode and CIDER are available for Emacs .
  • For Vim there is VimClojure.

literature

Web links

Wikibooks: Clojure Programming  - Learning and teaching materials (English)

Individual evidence

  1. github.com
  2. ^ Rich Hickey: Books that influenced Clojure . June 30, 2009. Retrieved August 24, 2010.
  3. leiningen.org
  4. github.com
  5. github.com
  6. Light Table
  7. cursive
  8. Counterclockwise
  9. vs Clojure
  10. ^ Clojure fashion
  11. CIDER
  12. Vim Clojure