The Joy of Clojure
Michael Fogus and Chris Houser
  • March 2011
  • ISBN 9781935182641
  • 360 pages
  • printed in black & white
This title is out of print and no longer for sale.

You'll learn fast!

Steve Yegge, Google

Second edition of this book is available

The Joy of Clojure goes beyond just syntax to show you how to write fluent and idiomatic Clojure code. You'll learn a functional approach to programming and will master Lisp techniques that make Clojure so elegant and efficient. The book gives you easy access to hard soft ware areas like concurrency, interoperability, and performance. And it shows you how great it can be to think about problems the Clojure way.

Table of Contents detailed table of contents




about this book


Part 1 Foundations

1. Clojure philosophy

1.1. The Clojure way

1.2. Why a(nother) Lisp?

1.3. Functional programming

1.4. Why Clojure isn’t especially object-oriented

1.5. Summary

2. Drinking from the Clojure firehose

2.1. Scalars

2.2. Putting things together: collections

2.3. Making things happen: functions

2.4. Vars

2.5. Locals, loops, and blocks

2.6. Preventing things from happening: quoting

2.7. Leveraging Java via interop

2.8. Exceptional circumstances

2.9. Namespaces

2.10. Summary

3. Dipping our toes in the pool

3.1. Truthiness

3.2. Nil pun with care

3.3. Destructuring

3.4. Using the REPL to experiment

3.5. Summary

Part 2 Data types

4. On scalars

4.1. Understanding precision

4.2. Trying to be rational

4.3. When to use keywords

4.4. Symbolic resolution

4.5. Regular expressions—the second problem

4.6. Summary

5. Composite data types

5.1. Persistence, sequences, and complexity

5.2. Vectors: creating and using them in all their varieties

5.3. Lists: Clojure’s code form data structure

5.4. How to use persistent queues

5.5. Persistent sets

5.6. Thinking in maps

5.7. Putting it all together: finding the position of items in a sequence

5.8. Summary

Part 3 Functional programming

6. Being lazy and set in your ways

6.1. On immutability

6.2. Designing a persistent toy

6.3. Laziness

6.4. Putting it all together: a lazy quicksort

6.5. Summary

7. Functional programming

7.1. Functions in all their forms

7.2. Closures

7.3. Thinking recursively

7.4. Putting it all together: A* pathfinding

7.5. Summary

Part 4 Large-scale design

8. Macros

8.1. Data is code is data

8.2. Defining control structures

8.3. Macros combining forms

8.4. Using macros to change forms

8.5. Using macros to control symbolic resolution time

8.6. Using macros to manage resources

8.7. Putting it all together: macros returning functions

8.8. Summary

9. Combining data and code

9.1. Namespaces

9.2. Exploring Clojure multimethods with the Universal Design Pattern

9.3. Types, protocols, and records

9.4. Putting it all together: a fluent builder for chess moves

9.5. Summary


10.1. Generating objects on the fly with proxy

10.2. Clojure gen-class and GUI programming

10.3. Clojure’s relationship to Java arrays

10.4. All Clojure functions implement…​

10.5. Using Clojure data structures in Java APIs

10.6. definterface

10.7. Be wary of exceptions

10.8. Summary

11. Mutation

11.1. Software transactional memory with multiversion concurrency control and snapshot isolation

11.2. When to use Refs

11.3. When to use Agents

11.4. When to use Atoms

11.5. When to use locks

11.6. When to use futures

11.7. When to use promises

11.8. Parallelism

11.9. Vars and dynamic binding

11.10. Summary

Part 5 Tangential considerations

12. Performance

12.1. Type hints

12.2. Transients

12.3. Chunked sequences

12.4. Memoization

12.5. Understanding coercion

12.6. Summary

13. Clojure changes the way you think

13.1. DSLs

13.2. Testing

13.3. A lack of design patterns

13.4. Error handling and debugging

13.5. Fare thee well



About the Technology

If you've seen how dozens of lines of Java or Ruby can dissolve into just a few lines of Clojure, you'll know why the authors of this book call it a "joyful language." Clojure is a dialect of Lisp that runs on the JVM. It combines the nice features of a scripting language with the powerful features of a production environment—features like persistent data structures and clean multithreading that you'll need for industrial-strength application development.

What's inside

  • The what and why of Clojure
  • How to work with macros
  • How to do elegant application design
  • Functional programming idioms

About the reader

Written for programmers coming to Clojure from another programming background—no prior experience with Clojure or Lisp is required.

About the authors

Michael Fogus is a member of Clojure/core with experience in distributed simulation, machine vision, and expert systems. Chris Houser is a key contributor to Clojure who has implemented several of its features.

Simply unputdownable!

Baishampayan Ghose, Qotd, Inc.

Discover the why, not just the how of Clojure.

Federico Tomassetti, Politecnico di Torino

What Irma Rombauer did for cooking, Fogus and Houser have done for Clojure.

Phil Hagelberg, Sonian