Programming Clojure, 3rd Edition

Book description

Drowning in unnecessary complexity, unmanaged state, and tangles of spaghetti code? In the best tradition of Lisp, Clojure gets out of your way so you can focus on expressing simple solutions to hard problems. Clojure cuts through complexity by providing a set of composable tools--immutable data, functions, macros, and the interactive REPL. Written by members of the Clojure core team, this book is the essential, definitive guide to Clojure. This new edition includes information on all the newest features of Clojure, such as transducers and specs.

Clojure joins the flexibility and agility of Lisp with the reach, stability, and performance of Java. Combine Clojure's tools for maximum effectiveness as you work with immutable data, functional programming, and safe concurrency to write programs that solve real-world problems.

Start by reading and understanding Clojure syntax and see how Clojure is evaluated. From there, find out about the sequence abstraction, which combines immutable collections with functional programming to create truly reusable data transformation code. Clojure is a functional language; learn how to write programs in a functional style, and when and how to use recursion to your advantage. Discover Clojure's unique approach to state and identity, techniques for polymorphism and open systems using multimethods and protocols, and how to leverage Clojure's metaprogramming capabilities via macros. Finally, put all the pieces together in a real program.

New to this edition is coverage of Clojure's spec library, one of the most interesting new features of Clojure for describing both data and functions. You can use Clojure spec to validate data, destructure data, explain invalid data, and generate large numbers of tests to verify the correctness of your code.

With this book, you'll learn how to think in Clojure, and how to take advantage of its combined strengths to build powerful programs quickly.

What You Need:

  • Java 6 or higher
  • Clojure 1.9
  • Publisher resources

    View/Submit Errata

    Table of contents

    1.  Acknowledgments
    2.  Introduction
      1. Who This Book Is For
      2. What’s in This Book
      3. How to Read This Book
      4. Notation Conventions
      5. Web Resources and Feedback
      6. Downloading Sample Code
    3. 1. Getting Started
      1. Simplicity and Power in Action
      2. Clojure Coding Quick Start
      3. Navigating Clojure Libraries
      4. Wrapping Up
    4. 2. Exploring Clojure
      1. Reading Clojure
      2. Functions
      3. Vars, Bindings, and Namespaces
      4. Metadata
      5. Calling Java
      7. Flow Control
      8. Where’s My for Loop?
      9. Wrapping Up
    5. 3. Unifying Data with Sequences
      1. Everything Is a Sequence
      2. Using the Sequence Library
      3. Lazy and Infinite Sequences
      4. Clojure Makes Java Seq-able
      5. Calling Structure-Specific Functions
      6. Wrapping Up
    6. 4. Functional Programming
      1. Functional Programming Concepts
      2. How to Be Lazy
      3. Lazier Than Lazy
      4. Recursion Revisited
      5. Eager Transformations
      6. Wrapping Up
    7. 5. Specifications
      1. Defining Specs
      2. Validating Data
      3. Validating Functions
      4. Generative Function Testing
      5. Wrapping Up
    8. 6. State and Concurrency
      1. Concurrency, Parallelism, and Locking
      2. Refs and Software Transactional Memory
      3. Use Atoms for Uncoordinated, Synchronous Updates
      4. Use Agents for Asynchronous Updates
      5. Managing Per-Thread State with Vars
      6. A Clojure Snake
      7. Wrapping Up
    9. 7. Protocols and Datatypes
      1. Programming to Abstractions
      2. Interfaces
      3. Protocols
      4. Datatypes
      5. Records
      6. reify
      7. Wrapping Up
    10. 8. Macros
      1. When to Use Macros
      2. Writing a Control Flow Macro
      3. Making Macros Simpler
      4. Taxonomy of Macros
      5. Wrapping Up
    11. 9. Multimethods
      1. Living Without Multimethods
      2. Defining Multimethods
      3. Moving Beyond Simple Dispatch
      4. Creating Ad Hoc Taxonomies
      5. When Should I Use Multimethods?
      6. Wrapping Up
    12. 10. Java Interop
      1. Creating Java Objects in Clojure
      2. Calling Clojure From Java
      3. Exception Handling
      4. Optimizing for Performance
      5. A Real-World Example
      6. Wrapping Up
    13. 11. Building an Application
      1. Getting Started
      2. Developing the Game Loop
      3. Representing Progress
      4. Implementing Players
      5. Interactive Play
      6. Documenting and Testing Your Game
      7. Farewell
    14.  Bibliography

    Product information

    • Title: Programming Clojure, 3rd Edition
    • Author(s): Alex Miller, Stuart Halloway, Aaron Bedra
    • Release date: February 2018
    • Publisher(s): Pragmatic Bookshelf
    • ISBN: 9781680502466