codefinance.training

Coding for Finance

Clojure

Clojure

Tab nameTab nameTab name
Tab content
Tab content
Tab content
AboutBooks

Clojure (/ˈklʒər/, like closure)[17][18] is a dynamic and functional dialect of the Lisp programming language on the Java platform.[19][20]

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.[21][17] Clojure's reader supports literal syntax for maps, sets and vectors along with lists, and these are compiled to the mentioned structures directly.[21] Clojure treats code as data and has a Lisp macro system.[22] 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.[22]

Clojure advocates immutability and immutable data structures and encourages programmers to be explicit about managing identity and its states.[23] This focus on programming with immutable values and explicit progression-of-time constructs is intended to facilitate developing more robust, especially concurrent, programs that are simple and fast.[24][25][17] While its type system is entirely dynamic, recent efforts have also sought the implementation of a dependent type system.[26]

The language was created by Rich Hickey in the mid-2000s, originally for the Java platform; the language has since been ported to other platforms, such as the Common Language Runtime (.NET). Hickey continues to lead development of the language as its benevolent dictator for life.

History

Rich Hickey, creator of Clojure

Rich Hickey is the creator of the Clojure language.[19] Before Clojure, he developed dotLisp, a similar project based on the .NET platform,[27] and three earlier attempts to provide interoperability between Lisp and Java: a Java foreign language interface for Common Lisp (jfli),[28] A Foreign Object Interface for Lisp (FOIL),[29] and a Lisp-friendly interface to Java Servlets (Lisplets).[30]

Hickey spent about two and a half years working on Clojure before releasing it publicly in October 2007,[31] 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.

Clojure's name, according to Hickey, is a word play on the programming concept "closure" incorporating the letters C, L, and J for C#, Lisp, and Java respectively—three languages which had a major influence on Clojure's design.[18]

Design

Rich Hickey developed Clojure because he wanted a modern Lisp for functional programming, symbiotic with the established Java platform, and designed for concurrency.[24][25][32][17] He has also stressed the importance of simplicity in programming language design and software architecture, advocating for loose coupling, polymorphism via protocols and type classes instead of inheritance, stateless functions that are namespaced instead of methods or replacing syntax with data.[33][34][35]

Clojure's approach to state is characterized by the concept of identities,[23] 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.[23]

Clojure runs on the Java platform and as a result, integrates with Java and fully supports calling Java code from Clojure,[36][17] and Clojure code can be called from Java, too.[37] The community uses tools such as Clojure command-line interface (CLI)[38] or Leiningen for project automation, providing support for Maven integration. These tools handle project package management and dependencies and are configured using Clojure syntax.

As a Lisp dialect, Clojure supports functions as first-class objects, a read–eval–print loop (REPL), and a macro system.[6] Clojure's Lisp macro system is very similar to that of 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.[39] Clojure supports multimethods[40] and for interface-like abstractions has a protocol[41] based polymorphism and data type system using records,[42] 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;[43][44][45] it is possible to do so explicitly by using the recur keyword.[46] For parallel and concurrent programming Clojure provides software transactional memory,[47] a reactive agent system,[1] and channel-based concurrent programming.[48]

Clojure 1.7 introduced reader conditionals by allowing the embedding of Clojure, ClojureScript and ClojureCLR code in the same namespace.[49][21] 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.[50][51][52]

Extensible Data Notation

Extensible Data Notation, or edn,[53] is a subset of the Clojure language intended as a data transfer format. It can be used to serialize and deserialize Clojure data structures, and Clojure itself uses a superset of edn to represent programs.

edn is used in a similar way to JSON or XML, but has a relatively large list of built-in elements, shown here with examples:

  • booleans: true, false
  • strings: "foo bar"
  • characters: \c, \tab
  • symbols: name
  • keywords: :key
  • integers: 123
  • floating point numbers: 3.14
  • lists: (a b 42)
  • vectors: [a b 42]
  • maps: {:a 1, "foo" :bar, [1 2 3] four}
  • sets: #{a b [1 2 3]}
  • nil: nil (a null-like value)

In addition to those elements, it supports extensibility through the use of tags, which consist of the character # followed by a symbol. When encountering a tag, the reader passes the value of the next element to the corresponding handler, which returns a data value. For example, this could be a tagged element: #myapp/Person {:first "Fred" :last "Mertz"}, whose interpretation will depend on the appropriate handler of the reader.

This definition of extension elements in terms of the others avoids relying on either convention or context to convey elements not included in the base set.

Alternative platforms

The primary platform of Clojure is Java,[20][36] but other target implementations exist. The most notable of these is ClojureScript,[54] which compiles to ECMAScript 3,[55] and ClojureCLR,[56] a full port on the .NET platform, interoperable with its ecosystem.

Other implementations of Clojure on different platforms include:

  • Babashka,[57] Native Clojure scripting language leveraging GraalVM native image and Small Clojure Interpreter
  • CljPerl,[58] Clojure on Perl
  • ClojureDart,[59] Extend Clojure's reach to mobile & desktop apps by porting Clojure to Dart and Flutter
  • Clojerl,[60] Clojure on BEAM, the Erlang virtual machine
  • basilisp,[61] A Clojure-compatible(-ish) Lisp dialect targeting Python 3.8+
  • ClojureRS,[62] Clojure on Rust
  • Ferret,[63] compiles to self-contained C++11 that can run on microcontrollers
  • jank,[64] Native Clojure hosted in C++ on an LLVM-based JIT
  • Joker,[65] an interpreter and linter written in Go
  • Las3r,[66] a subset of Clojure that runs on the ActionScript Virtual Machine (the Adobe Flash Player platform)
  • Pixie,[67] Clojure-inspired Lisp dialect written in RPython
  • Rouge,[68] Clojure on YARV in Ruby

Tools

Tooling for Clojure development has seen significant improvement over the years. The following is a list of some popular IDEs and text editors with plug-ins that add support for programming in Clojure:[69]

In addition to the tools provided by the community, the official Clojure command-line interface (CLI) tools[38] have also become available on Linux, macOS, and Windows since Clojure 1.9.[83]

Development

The development process is restricted to the Clojure core team, though issues are publicly visible at the Clojure JIRA project page.[84] Anyone can ask questions or submit issues and ideas at ask.clojure.org.[85] If it's determined that a new issue warrants a JIRA ticket, a core team member will triage it and add it. JIRA issues are processed by a team of screeners and finally approved by Rich Hickey.[86][87]

Impact

With continued interest in functional programming, Clojure's adoption by software developers using the Java platform has continued to increase. The language has also been recommended by software developers such as Brian Goetz,[88][89][90] Eric Evans,[91][92] James Gosling,[93] Paul Graham,[94] and Robert C. Martin.[95][96][97][98] ThoughtWorks, while assessing functional programming languages for their Technology Radar,[99] described Clojure as "a simple, elegant implementation of Lisp on the JVM" in 2010 and promoted its status to "ADOPT" in 2012.[100]

In the "JVM Ecosystem Report 2018" (which was claimed to be "the largest survey ever of Java developers"), that was prepared in collaboration by Snyk and Java Magazine, ranked Clojure as the 2nd most used programming language on the JVM for "main applications".[101] Clojure is used in industry by firms[102] such as Apple,[103][104] Atlassian,[105] Funding Circle,[106] Netflix,[107] Nubank,[108] Puppet,[109] and Walmart[110] as well as government agencies such as NASA.[111] It has also been used for creative computing, including visual art, music, games, and poetry.[112]

In the 2023 edition of Stack Overflow Developer Survey, Clojure was the fourth most admired in the category of programming and scripting languages, with 68.51% of the respondents who have worked with it last year saying they would like to continue using it. In the desired category, however it was marked as such by only 2.2% of the surveyed, whereas the highest scoring JavaScript was desired by 40.15% of the developers participating in the survey.[113] It could possibly be attributed to limited professional opportunities for Clojure developers with just over 50 search results for "Clojure developer" at the U.S. section of Indeed, as of May 2024.[114]

Release history

See also

References

  1. ^ a b "Agents and Asynchronous Actions". Clojure.org. Retrieved 2019-07-07.
  2. ^ "Concurrent Programming". Clojure.org. Retrieved 2019-07-07.
  3. ^ Hickey, Rich; contributors. "core.async". GitHub. Retrieved 2019-07-07.
  4. ^ "Functional Programming". Clojure.org. Retrieved 2019-07-07.
  5. ^ Nolen, David; Hickey, Rich. "core.logic". GitHub. Retrieved 2019-07-07.
  6. ^ a b "Macros". Clojure.org. Retrieved 2019-07-07.
  7. ^ Esterhazy, Paulus. "Threading Macros Guide". Clojure.org. Retrieved 2019-07-07.
  8. ^ a b Miller, Alex (2024-03-08). "Clojure 1.11.2 release". Clojure.org.
  9. ^ Fogus, Michael (2011). "Rich Hickey Q&A". CodeQuarterly.com. Archived from the original on 2017-01-11.
  10. ^ Hickey, Rich (2011). "Simple Made Easy". YouTube. {{cite web}}: Unknown parameter |note= ignored (help)
  11. ^ Bonnaire-Sergeant, Ambrose (2012). A Practical Optional Type System for Clojure (Thesis). The University of Western Australia.
  12. ^ "Clojure Programming" (PDF). OReilly.com. Retrieved 2013-04-30.
  13. ^ Hickey, Rich. "Clojure Bookshelf". Amazon.com. Archived from the original on 2017-10-03. Retrieved 2019-07-07.
  14. ^ Rose, Calvin; contributors. "Janet Language". Janet-Lang.org. Retrieved 2023-02-18.
  15. ^ Baldridge, Timothy. "Pixie". PixieLang.org. Retrieved 2019-07-07.
  16. ^ Ramachandra, Ramkumar. "Rhine". GitHub. Retrieved 2019-07-07.
  17. ^ a b c d e Edwards, Kathryn (2009-08-10). "The A-Z of Programming Languages: Clojure". Computerworld.com.au. Archived from the original on 2019-08-26.
  18. ^ a b Hickey, Rich (2009-01-05). "meaning and pronunciation of Clojure". Google.com.
  19. ^ a b Krill, Paul (2012-03-22). "Clojure inventor Hickey now aims for Android". InfoWorld.com.
  20. ^ a b "Clojure". Clojure.org. Retrieved 2019-07-07.
  21. ^ a b c "The Reader". Clojure.org. Retrieved 2019-07-07.
  22. ^ a b "Differences with other Lisps". Clojure.org. Retrieved 2019-07-07.
  23. ^ a b c "Values and Change: Clojure's approach to Identity and State". Clojure.org. Retrieved 2019-07-07.
  24. ^ a b Hickey, Rich. "Rationale". Clojure.org. Retrieved 2019-07-07.
  25. ^ a b Torre, Charles (2009-10-06). "Expert to Expert: Rich Hickey and Brian Beckman – Inside Clojure". MSDN.com.
  26. ^ "clojure/spec.alpha". GitHub. 2017-04-26.
  27. ^ Hickey, Rich (2002-10-16). "[ANN] dotLisp: A Lisp dialect for .Net". Google.com.
  28. ^ Hickey, Rich (2013-04-15). "jfli". SourceForge.net.
  29. ^ Hickey, Rich (2013-04-03). "foil: Foreign Object Interface for Lisp". SourceForge.net.
  30. ^ Hickey, Rich (2013-03-07). "Lisplets". SourceForge.net.
  31. ^ a b Hickey, Rich (2020-06-12). "A history of Clojure". Proceedings of the ACM on Programming Languages. 4 (HOPL): 1–46. doi:10.1145/3386321. S2CID 219603760.
  32. ^ Elmendorf, Dirk (2010-04-01). "Economy Size Geek – Interview with Rich Hickey, Creator of Clojure". LinuxJournal.com.
  33. ^ "Simple Made Easy". InfoQ. Retrieved 2024-05-02.
  34. ^ "(iterate think thoughts): Advantages of Data Oriented Programming". yogthos.net. Retrieved 2024-05-02.
  35. ^ "talk-transcripts/Hickey_Rich/EffectivePrograms.md at master · matthiasn/talk-transcripts". GitHub. Retrieved 2024-05-02.
  36. ^ a b "Hosted on the JVM". Clojure.org. Retrieved 2019-07-07.
  37. ^ "Java Interop". Clojure.org. Retrieved 2019-07-07.
  38. ^ a b Miller, Alex. "Deps and CLI Guide". Clojure.org. Retrieved 2019-07-08.
  39. ^ Hickey, Rich. "edn". GitHub. Retrieved 2019-07-07.
  40. ^ "Multimethods and Hierarchies". Clojure.org. Retrieved 2019-07-07.
  41. ^ "Protocols". Clojure.org. Retrieved 2019-07-07.
  42. ^ "Datatypes: deftype, defrecord and reify". Clojure.org. Retrieved 2019-07-07.
  43. ^ Goetz, Brian (2014-11-20). "Stewardship: the Sobering Parts". YouTube.com.
  44. ^ Rose, John (2007-07-12). "tail calls in the VM". Oracle.com.
  45. ^ Rose, John (2009-02-11). "Some languages need to be able to perform tail calls". Java.net.
  46. ^ "Special Forms". Clojure.org. Retrieved 2019-07-07.
  47. ^ "Refs and Transactions". Clojure.org. Retrieved 2019-07-07.
  48. ^ Hickey, Rich (2013-06-28). "Clojure core.async Channels". Clojure.org.
  49. ^ a b Miller, Alex (2015-06-30). "Clojure 1.7 is now available". Clojure.org.
  50. ^ Hickey, Rich (2014-09-17). "Transducers". YouTube.com.
  51. ^ Hickey, Rich (2014-08-06). "Transducers are Coming". Cognitect.com.
  52. ^ Hickey, Rich (2014-11-20). "Inside Transducers". YouTube.com.
  53. ^ "Official EDN Spec". edn-format.org. 2022-04-27.
  54. ^ "ClojureScript". ClojureScript.org. Retrieved 2019-07-06.
  55. ^ "ClojureScript – FAQ (for JavaScript developers)". ClojureScript.org. Retrieved 2018-02-04.
  56. ^ "ClojureCLR". GitHub. Retrieved 2012-06-28.
  57. ^ Borkent, Michiel. "Babashka". Babashka.org. Retrieved 2019-08-19.
  58. ^ Hu, Wei. "A Lisp on Perl". MetaCPAN.org. Retrieved 2019-07-06.
  59. ^ "What is ClojureDart?", GitHub, Tensegritics, 2022-12-16, retrieved 2022-12-16
  60. ^ Facorro, Juan. "Clojerl". GitHub. Retrieved 2019-07-06.
  61. ^ "basilisp". GitHub. Retrieved 2024-05-13.
  62. ^ "ClojureRS". GitHub. Retrieved 2022-03-17.
  63. ^ Akkaya, Nurullah. "Ferret". Ferret-Lang.org. Retrieved 2019-07-06.
  64. ^ Wilkerson, Jeaye. "jank". Jank-Lang.org. Retrieved 2022-08-17.
  65. ^ Bataev, Roman. "Joker". Joker-Lang.org. Retrieved 2019-07-06.
  66. ^ Cannon, Aemon. "Laz3r". GitHub. Retrieved 2019-07-06.
  67. ^ Baldridge, Timothy. "Pixie". PixieLang.org. Retrieved 2019-07-06.
  68. ^ Connor, Ashe. "Rouge". GitHub. Retrieved 2019-07-06.
  69. ^ Miller, Alex (2019-02-04). ""State of Clojure 2019" Results". Clojure.org.
  70. ^ Batsov, Bozhidar; contributors. "CIDER: The Clojure Interactive Development Environment that Rocks". CIDER.mx. Retrieved 2019-07-05.
  71. ^ Fleming, Colin. "Cursive: Provides full Clojure and ClojureScript language support". JetBrains.com. Retrieved 2019-07-05.
  72. ^ Prokopov, Nikita. "Clojure Sublimed". PackageControl.io. Retrieved 2023-02-18.
  73. ^ Helenius, Eero. "Tutkain". FlowThing.me. Retrieved 2023-02-18.
  74. ^ Pope, Tim. "fireplace.vim: Clojure REPL Support". VIM.org. Retrieved 2019-07-05.
  75. ^ Monroe, Dominic (2016-12-13). "Clojure and Vim: An overview – It's very possible". JUXT.pro.
  76. ^ Masashi, Iizuka (2024-04-29). "vim-elin: A Clojure development environment for Vim/Neovim, primarily written in Babashka". GitHub. Archived from the original on 2024-05-02. Retrieved 2024-05-02.
  77. ^ Caldwell, Oliver. "Neovim Clojure(Script) tooling over prepl". GitHub. Retrieved 2019-11-09.
  78. ^ Caldwell, Oliver (2019-11-06). "Getting started with Clojure, Neovim and Conjure in minutes". oli.me.uk.
  79. ^ Strömberg, Peter. "Calva: Clojure & ClojureScript Interactive Programming". VisualStudio.com. Retrieved 2019-07-05.
  80. ^ Szabo, Maurício. "Clover". VisualStudio.com. Retrieved 2021-01-28.
  81. ^ clj-kondo/clj-kondo, clj-kondo, 2024-04-30, retrieved 2024-05-02
  82. ^ "Overview - Clojure LSP". clojure-lsp.io. Retrieved 2024-05-02.
  83. ^ Miller, Alex (2017-12-08). "Clojure 1.9". Cognitect.com.
  84. ^ "Clojure". Atlassian.net. Retrieved 2019-07-07.
  85. ^ "Clojure Forum". clojure.org. Retrieved 2020-03-20.
  86. ^ Hickey, Rich (2018-11-26). "Open Source is Not About You". GitHub.
  87. ^ "Workflow". Clojure.org. Retrieved 2019-07-07.
  88. ^ Goetz, Brian (2020-05-24). "Brian Goetz' favorite non-Java JVM language (Part 1 of 3)". Twitch.tv.
  89. ^ Goetz, Brian (2020-05-24). "Brian Goetz' favorite non-Java JVM language (Part 2 of 3)". Twitch.tv.
  90. ^ Goetz, Brian (2020-05-24). "Brian Goetz' favorite non-Java JVM language (Part 3 of 3)". Twitch.tv.
  91. ^ Evans, Eric (2018-08-14). "Modelling Time: Eric Evans: Domain-Driven Design Europe 2018". YouTube.com.
  92. ^ Evans, Eric (2014-11-21). "Eric Evans on Twitter". Twitter.com.
  93. ^ "James Gosling meetup with London Java Community". YouTube.com. 2016-10-11.
  94. ^ Graham, Paul (2016-05-06). "Paul Graham on Twitter". Twitter.com.
  95. ^ Martin, Robert (2019-08-22). "Why Clojure?". CleanCoder.com.
  96. ^ Martin, Robert (2018-11-29). "Unble Bob Martin on Twitter". Twitter.com.
  97. ^ Martin, Robert (2018-08-01). "Introduction To Functional Programming". CleanCoders.com.
  98. ^ Martin, Robert (2017-07-11). "Pragmatic Functional Programming". CleanCoder.com.
  99. ^ "Technology Radar | An opinionated guide to today's technology landscape". Thoughtworks. Retrieved 2024-05-20.
  100. ^ "Technology Radar: Clojure". ThoughtWorks.com. Retrieved 2019-02-10.
  101. ^ Maple, Simon; Binstock, Andrew (2018-10-17). "JVM Ecosystem Report 2018". Snyk.io.
  102. ^ "Success Stories". Clojure.org. Retrieved 2018-10-27.
  103. ^ Liutikov, Roman (2017-12-17). "Roman Liutikov on Twitter". Twitter.com.
  104. ^ "Jobs at Apple". Apple.com. Retrieved 2019-07-06.
  105. ^ Borges, Leonardo (2015-07-07). "Realtime Collaboration with Clojure". YouTube.com.
  106. ^ Pither, Jon (2016-10-04). "Clojure in London: Funding Circle – Lending some Clojure". JUXT.pro.
  107. ^ Williams, Alex (2014-08-03). "The New Stack Makers: Adrian Cockcroft on Sun, Netflix, Clojure, Go, Docker and More". TheNewStack.io.
  108. ^ "Nubank adquire empresa norte-americana de tecnologia Cognitect". 23 July 2020.
  109. ^ Price, Chris (2014-04-11). "A New Era of Application Services at Puppet Labs". Puppet.com. Retrieved 2020-08-06.
  110. ^ Phillips, Marc (2015-07-14). "Walmart Runs Clojure at Scale". Cognitect.com.
  111. ^ "Common-Metadata-Repository". GitHub. Retrieved 2019-07-06.
  112. ^ Meier, Carin (2015-05-06). "Creative computing with Clojure". OReilly.com.
  113. ^ "Stack Overflow Developer Survey 2023". Stack Overflow. Retrieved 2024-05-02.
  114. ^ ""Clojure developer" search results at Indeed.com [Archived due to the mutability of the source]". Archive.is. 2024-05-02. Retrieved 2024-05-02.
  115. ^ Hickey, Rich (2009-05-04). "Clojure 1.0". BlogSpot.com.
  116. ^ Hickey, Rich (2009-12-31). "Clojure 1.1 Release". BlogSpot.com.
  117. ^ Hickey, Rich (2010-08-19). "Clojure 1.2 Release". Google.com.
  118. ^ Redinger, Christopher (2011-09-23). "[ANN] Clojure 1.3 Released". Google.com.
  119. ^ Dipert, Alan (2012-04-17). "[ANN] Clojure 1.4 Released". Google.com.
  120. ^ Halloway, Stuart (2013-03-01). "ANN: Clojure 1.5". Google.com.
  121. ^ Halloway, Stuart (2013-03-10). "Clojure 1.5.1". Google.com.
  122. ^ Miller, Alex (2014-03-25). "[ANN] Clojure 1.6". Google.com.
  123. ^ Miller, Alex (2016-01-19). "Clojure 1.8 is now available". Clojure.org.
  124. ^ Miller, Alex (2017-12-08). "Clojure 1.9 is now available". Clojure.org.
  125. ^ Miller, Alex (2018-12-17). "Clojure 1.10 release". Clojure.org.
  126. ^ Miller, Alex (2019-06-06). "Clojure 1.10.1 release". Clojure.org.
  127. ^ Miller, Alex (2021-01-26). "Clojure 1.10.2 release". Clojure.org.
  128. ^ Miller, Alex (2021-03-04). "Clojure 1.10.3 release". Clojure.org.
  129. ^ Miller, Alex (2022-03-22). "Clojure 1.11.0 release". Clojure.org.
  130. ^ Miller, Alex (2022-04-05). "Clojure 1.11.1 release". Clojure.org.

Further reading

External links

Clojure for Finance

Clojure for Finance:
Timothy Washington -
There aren't many books on Clojure for Finance. Someone should write a better one.

Programming Clojure

Programming Clojure:
The Pragmatic Programmers Series.

Chas Emerick, Brian Carper & Christophe Grand -
Written by members of the Clojure core team, this book is the essential, definitive guide to Clojure.

Hands-On Reactive Programming with Clojure

Hands-On Reactive Programming with Clojure:
Create asynchronous, event-based, and concurrent applications, 2nd Edition

Konrad Szydlo and Leonardo Borges -
By the end of the book, you will have gained all the knowledge you need to create applications using different Reactive Programming approaches.


Comments are closed.

Proudly powered by WordPress | Theme: Rockers by SpiceThemes