Computer Science

Clojure language

Clojure is a modern, dynamic, functional programming language that runs on the Java Virtual Machine (JVM). It is designed to be simple, concise, and expressive, with a focus on immutability and concurrency. Clojure is known for its powerful data structures, seamless Java interoperability, and functional programming features.

Written by Perlego with AI-assistance

8 Key excerpts on "Clojure language"

  • Book cover image for: Programming Language Explorations
    • Ray Toal, Rachel Rivera, Alexander Schneider, Eileen Choe(Authors)
    • 2016(Publication Date)
    CHAPTER 8
    Clojure
    Clojure is a “dynamic … general-purpose language, combining the approachability and interactive development of a scripting language with an efficient and robust infrastructure for multithreaded programming.” [56 ]
    First appeared 2007
    Creator Rich Hickey
    Notable versions 1.0 (2009) • 1.7 (2015)
    Recognized for Macros, Lisp-ness, Concurrency support, Java interoperability
    Notable uses Data mining, Artificial intelligence
    Tags Functional, Dynamic, Concurrent, Homoiconic
    Six words or less A Lisp for the JVM
    In the 1950s John McCarthy created Lisp. In doing so, he was said to have “[done] for computing something like what Euclid [had done] for geometry,” [46 ] written the “Maxwell’s Equations of software,” [34 ] and given the world “the greatest single programming language ever designed.” [113 ] Lisp, remarked Edsger Dijkstra, has “assisted a number of our most gifted fellow humans in thinking previously impossible thoughts.” [26 ]
    This chapter introduces Clojure. Clojure is a Lisp—a modern Lisp. It has a richer set of data structures than the original Lisp. It does a better job than most (if not all) other Lisp dialects in isolating side effects and implementing concurrent features. Clojure interoperates with Java, so your Clojure program has access to the entire Java platform. Your Clojure code can call Java libraries. Your Java code can execute Clojure-written code.
    After presenting our usual three introductory scripts, we will cover the basic data types of Clojure (there are quite a few of these) and devote some time to persistent data structures, and the use of transients
  • Book cover image for: Programming Language Explorations
    • Ray Toal, Rachel Rivera, Alexander Schneider, Eileen Choe(Authors)
    • 2016(Publication Date)
    C H A P T E R 8 Clojure Clojure is a “dynamic ... general-purpose language, combining the approachability and interactive development of a scripting language with an efficient and robust infrastructure for multithreaded programming.” [56] First appeared 2007 Creator Rich Hickey Notable versions 1.0 (2009) • 1.7 (2015) Recognized for Macros, Lisp-ness, Concurrency support, Java interoperability Notable uses Data mining, Artificial intelligence Tags Functional, Dynamic, Concurrent, Homoiconic Six words or less A Lisp for the JVM In the 1950s John McCarthy created Lisp. In doing so, he was said to have “[done] for computing something like what Euclid [had done] for geometry,” [46] written the “Maxwell’s Equations of software,” [34] and given the world “the greatest single programming language ever designed.” [113] Lisp, remarked Edsger Dijkstra, has “assisted a number of our most gifted fellow humans in thinking previously impossible thoughts.” [26] This chapter introduces Clojure. Clojure is a Lisp—a modern Lisp. It has a richer set of data structures than the original Lisp. It does a better job than most (if not all) other Lisp dialects in isolating side effects and implementing concurrent features. Clojure interoperates with Java, so your Clojure program has access to the entire Java platform. Your Clojure code can call Java libraries. Your Java code can execute Clojure-written code. After presenting our usual three introductory scripts, we will cover the basic data types of Clojure (there are quite a few of these) and devote some time to persistent data structures, and the use of transients to isolate mutable operations. We’ll then look at Clojure’s various approaches to concurrency (one of the language’s great strengths) visiting refs, agents, and software transactional memory.
  • Book cover image for: Introduction to JVM Languages

    Clojure

    Clojure is a language that is rather different from the other languages covered in this book. It is a language largely inspired by the Lisp programming language, which originally dates back to the late 1950s. Lisp stayed relevant by being up to date with both technology and times. Common Lisp and Scheme are arguably the two most popular Lisp dialects in use today. Clojure is a dialect of Lisp, but its design is influenced by both.
    Unlike Java and Scala, Clojure is a dynamic language. Variables do not have fixed types and when compiling, no type checking is performed by the compiler. When a variable is passed to a function that is not compatible with the code in the function, an exception will be thrown at runtime. What's also noteworthy is that Clojure is not an object-orientated language (OOP), unlike all the other languages in this book. Clojure still offers interoperability with Java and JVM, as it can create instances of objects. And, as we will soon see, it can also generate classes to let other Java-compatible languages on the JVM run the bytecode compiled by Clojure.
    We will cover the following topics here:
    • Installing Clojure
    • Clojure's interactive shell - Read-Eval-Print-Loop (REPL)
    • Clojure language basics
    • Working with classes
    • Clojure agent system
    Passage contains an image

    Installing Clojure

    From the official project's website (https://clojure.org/ ), download the latest version:
    It is recommended that you have the documentation available while trying the examples in this book. Both the online official documentation and the community-driven documentation sites are recommended:
    • http://clojure.org/reference/
    • http://clojure-doc.org
    At the time of writing, the latest version is Clojure 1.8.0. Extract the archive and write down the full path to the directory where you've extracted the archive; you'll need it to create a start script.
    To validate the installation, start the interactive shell. In the Command Prompt (Windows) or Terminal (macOS and Linux), replace the directory with Clojure's main directory and type the following command (replace the version number with your installed version):
  • Book cover image for: Clojure in Action
    eBook - ePub
    • Amit Rathore(Author)
    • 2015(Publication Date)
    • Manning
      (Publisher)
    The promise of Clojure’s synthesis of features is a language that’s composed of simple, comprehensible parts that not only provide power and flexibility to writing programs but also liberate your understanding of how the parts of a language can fit together. Let no one deceive you: there are many things to learn. Developing in Clojure requires learning how to read and write Lisp, a willingness to embrace a functional style of programming, and a basic understanding of the JVM and its runtime libraries. We’ll introduce all three of these Clojure pillars in this chapter to arm you for what lies ahead in the rest of the book: a deep dive into an incredible language that’s both new and old.
    1.1.1. Clojure: A modern Lisp
    Clojure is a fresh take on Lisp, one of the oldest programming language families still in active use (second only to Fortran). Lisp isn’t a single, specific language but rather a style of programming language that was designed in 1958 by Turing award winner John McCarthy. Today the Lisp family consists primarily of Common Lisp, Scheme, and Emacs Lisp, with Clojure as one of the newest additions. Despite its fragmented history, Lisp implementations, including Clojure, are used for cutting-edge software systems in various domains: NASA’s Pathfinder mission-planning software, algorithmic trading at hedge funds, flight-delay prediction, data mining, natural language processing, expert systems, bio-informatics, robotics, electronic design automation, web development, next-generation databases (http://www.datomic.com ), and many others.
    Clojure belongs to the Lisp family of languages, but it doesn’t adhere to any existing implementation exclusively, preferring instead to combine the strengths of several Lisps as well as features from languages like ML and Haskell. Lisp has the reputation of being a dark art, a secret weapon of success, and has been the birthplace of language features like conditionals, automatic garbage collection, macros, and functions as language values (not just procedures or subroutines; http://paulgraham.com/lisp.html
  • Book cover image for: Computer Programming Languages
    Scheme is a statically scoped and properly tail-recursive dialect of the Lisp programming language invented by Guy Lewis Steele Jr. and Gerald Jay Sussman. It was designed to have an exceptionally clear and simple semantics and few different ways to form ex- ________________________ WORLD TECHNOLOGIES ________________________ pressions. A wide variety of programming paradigms, including imperative, functional, and message passing styles, find convenient expression in Scheme. Scheme continues to evolve with a series of standards (Revised n Report on the Algorithmic Language Scheme) and a series of Scheme Requests for Implementation. Clojure is a dynamic programming dialect of Lisp that targets the Java Virtual Machine (and the CLR ). It is designed to be a general-purpose language, combining the app-roachability and interactive development of a scripting language with an efficient and robust infrastructure for multithreaded programming. Clojure is a compiled language, as it compiles directly to JVM bytecode, yet remains completely dynamic. Every feature supported by Clojure is supported at runtime. Clojure provides easy access to the Java frameworks, with optional type hints and type inference, to ensure that calls to Java can avoid reflection. In addition, Lisp dialects are used as scripting languages in a number of applications, with the most well-known being Emacs Lisp in the Emacs editor, Visual Lisp in Auto CAD, Nyquist in Audacity. The small size of a minimal but useful Scheme interpreter makes it particularly popular for embedded scripting. Examples include SIOD and TinyScheme, both of which have been successfully embedded in the GIMP image processor under the generic name Script-fu. LIBREP, a Lisp interpreter by John Harper originally based on the Emacs Lisp language, has been embedded in the Sawfish window manager.
  • Book cover image for: Clojure for Java Developers
    We will get to know Clojure by comparing each feature to what you already know from Java. You will see that there are lists, maps and sets just like in Java, but they are immutable. To work with these kinds of collections, you need a different approach; a different paradigm.
    This is what we will try to accomplish in this book, to give you a different way to approach problems. We hope you end up using Clojure in your every day life, but if you don't, we hope you use a new approach toward problem solving.
    In this chapter, we will cover the following topics:
    • Getting to know Clojure
    • Installing Leiningen
    • Using a Read Eval Print Loop (REPL )
    • Installing and using Cursive Clojure
    • Clojure's simple syntax
    • Clojure's data types and their relationship to the JVM's data types
    • Special syntax for functions

    Getting to know Clojure

    Before getting started with Clojure, you should know some of its features and what it shares with Java.
    Clojure is a programming language that inherits a lot of characteristics from Lisp. You might think of Lisp as that weird programming language with all the parentheses. You need to keep in mind that Clojure chooses to embrace functional programming. This makes it very different from current mainstream programming languages. You will get to know about immutable data structures and how to write programs without changing variable values.
    You will also find that Clojure is a dynamic programming language, which makes it a little easier and faster to write programs than using statically typed languages. There is also the concept of using a REPL, a tool that allows you to connect to a program running environment and change code dynamically. It is a very powerful tool.
    At last, you will find out that you can convert Clojure to anything you like. You can create or use a statically typed system and bend the language to become what you like. A good example of this is the core.typed
  • Book cover image for: The Well-Grounded Java Developer, Second Edition
    • Benjamin Evans, Martijn Verburg, Jason Clark(Authors)
    • 2022(Publication Date)
    • Manning
      (Publisher)
    For the avid reader who can’t wait until later, let us just say this: the concurrency abstractions enable programmers to write much safer multithreaded code than when working in Java. These abstractions can be combined with Clojure’s seq concept (a different take on collections and data structures) to provide a powerful developer toolbox.
    To access all of this power, some important language concepts are approached in a fundamentally different way from Java. This difference in approach makes Clojure interesting to learn, and it will probably also change the way you think about programming.
    Note Learning Clojure will help make you a better programmer in any language. Functional programming matters.
    We’ll kick off with a discussion of Clojure’s approach to state and variables. After some simple examples, we’ll introduce the basic vocabulary of the language—the special forms that are equivalent to keywords in languages like Java. A small number of these are used to build up the rest of the language.
    We’ll also delve into Clojure’s syntax for data structures, loops, and functions. This will allow us to introduce sequences, which are one of Clojure’s most powerful abstractions.
    We’ll conclude the chapter by looking at two very compelling features: tight Java integration and Clojure’s amazing macro support (which is the key to Lisp’s very flexible syntax). Later in the book, we’ll meet more Clojure goodness (as well as Kotlin and Java examples) when we talk about advanced functional programming (chapter 15) and advanced concurrency (chapter 16).

    10.1 Introducing Clojure

    The basic unit of Lisp syntax consists of an expression to be evaluated. These expressions are typically represented as zero or more symbols surrounded by brackets. If the evaluation succeeds without errors, the expression is called a form.
    Note
  • Book cover image for: The Clojure Workshop
    eBook - ePub

    The Clojure Workshop

    A New, Interactive Approach to Learning Clojure

    • Joseph Fahey, Thomas Haratyk, Scott McCaughie, Yehonathan Sharvit, Konrad Szydlo(Authors)
    • 2020(Publication Date)
    • Packt Publishing
      (Publisher)
    JVM ). The JVM is a host platform. Any programming language that compiles to Java bytecode can run on the JVM. Because Clojure compiles to Java bytecode and runs on the JVM, we call it a hosted language. Java dates from the 1990s and is now one of the most popular backend languages. We can leverage existing Java libraries instead of writing a lot of code on our own. This helps us deliver new features faster.
    As we will see, importing Java classes in Clojure is a bit different than using Clojure libraries. In this chapter, we will learn how to import and call Java classes in Clojure by writing an application that performs I/O operations—reading and writing from a file.
    In the second part of this chapter, we will look into ClojureScript and JavaScript interoperability. JavaScript is a scripting language that runs in browsers. It is the most popular frontend language at the moment. ClojureScript compiles to JavaScript. In ClojureScript, we can use JavaScript libraries. This gives us access to a huge amount of code written by other developers. A great boost to our productivity.

    Using Java in Clojure

    Any code written by a developer needs to be converted to code that is understood by a machine. An interpreter uses code from a developer and compiles it into machine code. Each operating system is different, hence the need for platform-specific compilers and interpreters. One of the reasons why Java is so successful is that it provides the JVM, which takes human-understandable code and converts it into machine code. Developers are not usually interested in the JVM. They can focus on writing code in Java without interacting with the underlying operating system. This job is done by the JVM.
    Clojure is a hosted language. It means that it uses the JVM instead of creating a new runtime environment. Clojure cleverly reuses facilities provided by the JVM. This is a very powerful approach. Things such as garbage collection, threading, concurrency, IO operations (all of which will be explained in the following paragraphs) are JVM battle-tested technologies that Clojure relies on.
Index pages curate the most relevant extracts from our library of academic textbooks. They’ve been created using an in-house natural language model (NLM), each adding context and meaning to key research topics.