Clojure
Clojure | |
---|---|
![]() 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
- Alex Miller with Stuart Halloway and Aaron Bedra: Programming Clojure - Third Edition . Pragmatic Programmers, 2018, ISBN 978-1-68050-246-6 .
- Rich Hickey: The Clojure programming language . In: Dynamic Languages Symposium archive, Proceedings of the 2008 symposium on Dynamic languages . July 2008, ISBN 978-1-60558-270-2 , doi: 10.1145 / 1408681.1408682 .
- Stefan Kamphausen, Tim Oliver Kaiser: Clojure . dpunkt.verlag, 2010, ISBN 978-3-89864-684-0 .
- Carin Meier: Living Clojure . O'Reilly, 2015, ISBN 978-1-4919-0904-1 .
- Chas Emerick, Brian Carper and Christophe Grand: Clojure Programming . O'Reilly, 2012, ISBN 978-1-4493-9470-7 .
Web links
- Official website of Clojure
- Clojure Documentation - collaboratively operated documentation project
- ClojureDocs - also a collaborative collection of documentation and examples
- Literature on Clojure
- Concurrent programming with Clojure . In: Linux-Magazin (German)
- Interactive online interpreter for Clojure and ClojureScript to try out
Individual evidence
- ↑ github.com
- ^ Rich Hickey: Books that influenced Clojure . June 30, 2009. Retrieved August 24, 2010.
- ↑ leiningen.org
- ↑ github.com
- ↑ github.com
- ↑ Light Table
- ↑ cursive
- ↑ Counterclockwise
- ↑ vs Clojure
- ^ Clojure fashion
- ↑ CIDER
- ↑ Vim Clojure