Английская Википедия:Clojure

Материал из Онлайн справочника
Перейти к навигацииПерейти к поиску

Шаблон:Short description Шаблон:Infobox programming language

Clojure (Шаблон:IPAc-en, like closure)[1][2] is a dynamic and functional dialect of the Lisp programming language on the Java platform.[3][4]

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

Clojure advocates immutability and immutable data structures and encourages programmers to be explicit about managing identity and its states.[7] 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.[8][9][1] While its type system is entirely dynamic, recent efforts have also sought the implementation of a dependent type system.[10]

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.jpg
Rich Hickey, creator of Clojure

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

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

Design

Rich Hickey developed Clojure because he wanted a modern Lisp for functional programming, symbiotic with the established Java platform, and designed for concurrency.[8][9][16][1]

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

Clojure runs on the Java platform and as a result, integrates with Java and fully supports calling Java code from Clojure,[17][1] and Clojure code can be called from Java, too.[18] The community uses tools such as Clojure command-line interface (CLI)[19] 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.[20] 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.[21] Clojure supports multimethods[22] and for interface-like abstractions has a protocol[23] based polymorphism and data type system using records,[24] 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;[25][26][27] it is possible to do so explicitly by using the recur keyword.[28] For parallel and concurrent programming Clojure provides software transactional memory,[29] a reactive agent system,[30] and channel-based concurrent programming.[31]

Clojure 1.7 introduced reader conditionals by allowing the embedding of Clojure, ClojureScript and ClojureCLR code in the same namespace.[32][5] 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.[33][34][35]

Extensible Data Notation

Extensible Data Notation, or edn,[36] 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,[4][17] but other target implementations exist. The most notable of these is ClojureScript,[37] which compiles to ECMAScript 3,[38] and ClojureCLR,[39] a full port on the .NET platform, interoperable with its ecosystem.

Other implementations of Clojure on different platforms include:

  • Babashka,[40] Native Clojure scripting language leveraging GraalVM native image and Small Clojure Interpreter
  • CljPerl,[41] Clojure on Perl
  • ClojureDart,[42] Extend Clojure's reach to mobile & desktop apps by porting Clojure to Dart and Flutter
  • Clojerl,[43] Clojure on BEAM, the Erlang virtual machine
  • clojure-py,[44] Clojure in pure Python
  • ClojureRS,[45] Clojure on Rust
  • Ferret,[46] compiles to self-contained C++11 that can run on microcontrollers
  • jank,[47] Native Clojure hosted in C++ on an LLVM-based JIT
  • Joker,[48] an interpreter and linter written in Go
  • Las3r,[49] a subset of Clojure that runs on the ActionScript Virtual Machine (the Adobe Flash Player platform)
  • Pixie,[50] Clojure-inspired Lisp dialect written in RPython
  • Rouge,[51] 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:[52]

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

Development

The development process is restricted to the Clojure core team, though issues are publicly visible at the Clojure JIRA project page.[65] Anyone can ask questions or submit issues and ideas at ask.clojure.org.[66] 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.[67][68]

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,[69][70][71] Eric Evans,[72][73] James Gosling,[74] Paul Graham,[75] and Robert C. Martin.[76][77][78][79] ThoughtWorks, while assessing functional programming languages for their Technology Radar,[80] described Clojure as "a simple, elegant implementation of Lisp on the JVM" in 2010 and promoted its status to "ADOPT" in 2012.[81]

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".[82] Clojure is used in industry by firms[83] such as Apple,[84][85] Atlassian,[86] Funding Circle,[87] Netflix,[88] Nubank,[89] Puppet,[90] and Walmart[91] as well as government agencies such as NASA.[92] It has also been used for creative computing, including visual art, music, games, and poetry.[93]

Release history

Version Release date Major features, improvements
Шаблон:Start date[15] Initial public release
1.0 Шаблон:Start date[94] First stable release
1.1 Шаблон:Start date[95] Futures
1.2 Шаблон:Start date[96] Protocols
1.3 Шаблон:Start date[97] Enhanced primitive support
1.4 Шаблон:Start date[98] Reader literals
1.5 Шаблон:Start date[99] Reducers
1.5.1 Шаблон:Start date[100] Fixing a memory leak
1.6 Шаблон:Start date[101] Java API, improved hashing algorithms
1.7 Шаблон:Start date[32] Transducers, reader conditionals
1.8 Шаблон:Start date[102] Additional string functions, direct linking, socket server
1.9 Шаблон:Start date[103] Integration with spec, command-line tools
1.10 Шаблон:Start date[104] Improved error reporting, Java compatibility
1.10.1 Шаблон:Start date[105] Working around a Java performance regression and improving error reporting from clojure.main
1.10.2 Шаблон:Start date[106] Java interoperability/compatibility improvements and other important language fixes
1.10.3 Шаблон:Start date[107] prepl support for reader conditionals
1.11.0 Шаблон:Start date[108] New syntax for keyword argument invocation, new clojure.math namespace, namespace aliasing without loading, and new helper functions added to clojure.core
Шаблон:Version Шаблон:Start date[109] Rolling back unintended change in binary serialisation of objects of types clojure.lang.Keyword and clojure.lang.ArraySeq.
Шаблон:Version

See also

Шаблон:Portal

References

Шаблон:Reflist

Further reading

Шаблон:Refbegin

Шаблон:Refend

External links

Шаблон:Lisp programming language Шаблон:Lisp Шаблон:Java (software platform)

Шаблон:Authority control

  1. 1,0 1,1 1,2 1,3 1,4 Шаблон:Cite web
  2. 2,0 2,1 Шаблон:Cite web
  3. 3,0 3,1 Шаблон:Cite web
  4. 4,0 4,1 Шаблон:Cite web
  5. 5,0 5,1 5,2 Шаблон:Cite web
  6. 6,0 6,1 Шаблон:Cite web
  7. 7,0 7,1 7,2 Шаблон:Cite web
  8. 8,0 8,1 Шаблон:Cite web
  9. 9,0 9,1 Шаблон:Cite web
  10. Шаблон:Cite web
  11. Шаблон:Cite web
  12. Шаблон:Cite web
  13. Шаблон:Cite web
  14. Шаблон:Cite web
  15. 15,0 15,1 Шаблон:Cite journal
  16. Шаблон:Cite web
  17. 17,0 17,1 Шаблон:Cite web
  18. Шаблон:Cite web
  19. 19,0 19,1 Шаблон:Cite web
  20. Ошибка цитирования Неверный тег <ref>; для сносок reference/macros не указан текст
  21. Шаблон:Cite web
  22. Шаблон:Cite web
  23. Шаблон:Cite web
  24. Шаблон:Cite web
  25. Шаблон:Cite web
  26. Шаблон:Cite web
  27. Шаблон:Cite web
  28. Шаблон:Cite web
  29. Шаблон:Cite web
  30. Ошибка цитирования Неверный тег <ref>; для сносок reference/agents не указан текст
  31. Шаблон:Cite web
  32. 32,0 32,1 Шаблон:Cite web
  33. Шаблон:Cite web
  34. Шаблон:Cite web
  35. Шаблон:Cite web
  36. Шаблон:Cite web
  37. Шаблон:Cite web
  38. Шаблон:Cite web
  39. Шаблон:Cite web
  40. Шаблон:Cite web
  41. Шаблон:Cite web
  42. Шаблон:Citation
  43. Шаблон:Cite web
  44. Шаблон:Cite web
  45. Шаблон:Cite web
  46. Шаблон:Cite web
  47. Шаблон:Cite web
  48. Шаблон:Cite web
  49. Шаблон:Cite web
  50. Шаблон:Cite web
  51. Шаблон:Cite web
  52. Шаблон:Cite web
  53. Шаблон:Cite web
  54. Шаблон:Cite web
  55. Шаблон:Cite web
  56. Шаблон:Cite web
  57. Шаблон:Cite web
  58. Шаблон:Cite web
  59. Шаблон:Cite web
  60. Шаблон:Cite web
  61. Шаблон:Cite web
  62. Шаблон:Cite web
  63. Шаблон:Cite web
  64. Шаблон:Cite web
  65. Шаблон:Cite web
  66. Шаблон:Cite web
  67. Шаблон:Cite web
  68. Шаблон:Cite web
  69. Шаблон:Cite web
  70. Шаблон:Cite web
  71. Шаблон:Cite web
  72. Шаблон:Cite web
  73. Шаблон:Cite web
  74. Шаблон:Cite web
  75. Шаблон:Cite web
  76. Шаблон:Cite web
  77. Шаблон:Cite web
  78. Шаблон:Cite web
  79. Шаблон:Cite web
  80. Шаблон:Cite web
  81. Шаблон:Cite web
  82. Шаблон:Cite web
  83. Шаблон:Cite web
  84. Шаблон:Cite web
  85. Шаблон:Cite web
  86. Шаблон:Cite web
  87. Шаблон:Cite web
  88. Шаблон:Cite web
  89. Шаблон:Cite web
  90. Шаблон:Cite web
  91. Шаблон:Cite web
  92. Шаблон:Cite web
  93. Шаблон:Cite web
  94. Шаблон:Cite web
  95. Шаблон:Cite web
  96. Шаблон:Cite web
  97. Шаблон:Cite web
  98. Шаблон:Cite web
  99. Шаблон:Cite web
  100. Шаблон:Cite web
  101. Шаблон:Cite web
  102. Шаблон:Cite web
  103. Шаблон:Cite web
  104. Шаблон:Cite web
  105. Шаблон:Cite web
  106. Шаблон:Cite web
  107. Шаблон:Cite web
  108. Шаблон:Cite web
  109. Шаблон:Cite web