Clojure Online Tutorials

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

Clojure
Paradigmmulti-paradigm:
  • agent-oriented
  • concurrent
  • functional
  • logic
  • macro
  • pipeline
FamilyLisp
Designed byRich Hickey
First appeared2007; 17 years ago (2007)
Stable release
1.11.2 / 8 March 2024; 41 days ago (2024-03-08)
Typing discipline
  • dynamic
  • strong
Platform
  • Java
  • JavaScript
  • .NET
LicenseEclipse Public
Filename extensions
  • .clj
  • .cljs
  • .cljr
  • .cljc
  • .edn
Websiteclojure.org
Influenced by
  • C#
  • C++
  • Common Lisp
  • Erlang
  • Haskell
  • Java
  • ML
  • Prolog
  • Racket
  • Ruby
  • Scheme
  • Wolfram Language
Influenced
  • Elixir
  • Hy
  • Janet
  • LFE
  • Pixie
  • Rhine
  • Clojure Programming at Wikibooks

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

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

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 edit

 
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, and three earlier attempts to provide interoperability between Lisp and Java: a Java foreign language interface for Common Lisp (jfli), A Foreign Object Interface for Lisp (FOIL), and a Lisp-friendly interface to Java Servlets (Lisplets).

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

Design edit

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

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.

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

Clojure 1.7 introduced reader conditionals by allowing the embedding of Clojure, ClojureScript and ClojureCLR 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.

Extensible Data Notation edit

Extensible Data Notation, or edn, 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:
  • maps: {:a 1, "foo" :bar, four}
  • sets: #{a b }
  • 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 edit

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

Other implementations of Clojure on different platforms include:

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

Tools edit

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:[65]

  • Emacs, with CIDER[66]
  • IntelliJ IDEA, with Cursive[67] (a free license is available for non-commercial use)
  • Sublime Text, with Clojure Sublimed,[68] or Tutkain,[69]
  • Vim, with fireplace.vim,[70][71] vim-iced,[72] or Conjure (Neovim only)[73][74]
  • Visual Studio Code, with Calva[75] or Clover[76]

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

Development edit

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

Impact edit

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,[82][83][84] Eric Evans,[85][86] James Gosling,[87] Paul Graham,[88] and Robert C. Martin.[89][90][91][92] ThoughtWorks, while assessing functional programming languages for their Technology Radar,[93] described Clojure as "a simple, elegant implementation of Lisp on the JVM" in 2010 and promoted its status to "ADOPT" in 2012.[94]

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".[95] Clojure is used in industry by firms[96] such as Apple,[97][98] Atlassian,[99] Funding Circle,[100] Netflix,[101] Nubank,[102] Puppet,[103] and Walmart[104] as well as government agencies such as NASA.[105] It has also been used for creative computing, including visual art, music, games, and poetry.[106]

Release history edit

Version Release date Major features, improvements
October 17, 2007 (2007-10-17)[30] Initial public release
1.0 May 4, 2009 (2009-05-04)[107] First stable release
1.1 December 31, 2009 (2009-12-31)[108] Futures
1.2 August 19, 2010 (2010-08-19)[109] Protocols
1.3 September 23, 2011 (2011-09-23)[110] Enhanced primitive support
1.4 April 15, 2012 (2012-04-15)[111] Reader literals
1.5 March 1, 2013 (2013-03-01)[112] Reducers
1.5.1 March 10, 2013 (2013-03-10)[113] Fixing a memory leak
1.6 March 25, 2014 (2014-03-25)[114] Java API, improved hashing algorithms
1.7 June 30, 2015 (2015-06-30)[45] Transducers, reader conditionals
1.8 January 19, 2016 (2016-01-19)[115] Additional string functions, direct linking, socket server
1.9 December 8, 2017 (2017-12-08)[116] Integration with spec, command-line tools
1.10 December 17, 2018 (2018-12-17)[117] Improved error reporting, Java compatibility
1.10.1 June 6, 2019 (2019-06-06)[118] Working around a Java performance regression and improving error reporting from clojure.main
1.10.2 January 26, 2021 (2021-01-26)[119] Java interoperability/compatibility improvements and other important language fixes
1.10.3 March 4, 2021 (2021-03-04)[120] prepl support for reader conditionals
1.11.0 March 22, 2022 (2022-03-22)[121] New syntax for keyword argument invocation, new clojure.math namespace, namespace aliasing without loading, and new helper functions added to clojure.core
1.11.1 April 5, 2022 (2022-04-05)[122] Rolling back unintended change in binary serialisation of objects of types clojure.lang.Keyword and clojure.lang.ArraySeq.
Current stable version: 1.11.2 March 8, 2024 (2024-03-08)[8] Fix for CVE CVE-2024-22871.
Legend:
Old version
Older version, still maintained
Latest version
Latest preview version
Future release

See also edit

  • List of JVM languages
  • List of CLI languages
  • Comparison of programming languages

Clojure Tutorials: Clojure is a modern Lisp dialect for the Java Virtual Machine (with versions for the CLR and JavaScript)

Latest online Clojure Tutorials with example so this page for both freshers and experienced candidate who want to get job in Clojure company

Latest online Clojure Tutorials for both freshers and experienced

advertisements

View Tutorials on Clojure View all questions

Ask your interview questions on Clojure

Write Your comment or Questions if you want the answers on Clojure from Clojure Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---