Programming Clojure, 2nd Edition is a significant update to the classic book on the Clojure language. Youll get thorough coverage of all the new features of Clojure 1.3, and enjoy reorganized and rewritten chapters that reflect the significance of new Clojure concepts. Many code examples have been rewritten or replaced, and every page has been reevaluated in the light of Clojure 1.3. As Aaron and Stu show you how to build an application from scratch, youll get a rich view into a complete Clojure workflow. And youll get an invaluable education in thinking in Clojure as you work out solutions to the various parts of a problem. Clojure is becoming the language of choice for many who are moving to functional programming or dealing with the challenges of concurrency. Clojure offers: The simplicity of an elegantly designed language The power of Lisp The virtues of concurrency and functional style The reach of the JVM The speed of hand-written Java code Its the combination of these features that makes Clojure sparkle. Programming Clojure, 2nd Edition shows you how to think in Clojure, and to take advantage of these combined strengths to build powerful programs quickly. What You Need: Oracle JDK 6 A text editor Cover 1 Table of Contents 7 Foreword for the Second Edition 10 Foreword for the First Edition 11 Acknowledgments 12 Preface 13 Who This Book Is For 13 What Is in This Book 14 How to Read This Book 15 Notation Conventions 16 Web Resources and Feedback 18 Downloading Sample Code 18 1. Getting Started 20 Why Clojure? 21 Clojure Coding Quick Start 30 Exploring Clojure Libraries 35 Wrapping Up 39 2. Exploring Clojure 40 Forms 40 Reader Macros 49 Functions 51 Vars, Bindings, and Namespaces 55 Calling Java 62 Flow Control 64 Where's My for Loop? 67 Metadata 70 Wrapping Up 72 3. Unifying Data with Sequences 73 Everything Is a Sequence 74 Using the Sequence Library 78 Lazy and Infinite Sequences 87 Clojure Makes Java Seq-able 89 Calling Structure-Specific Functions 94 Wrapping Up 102 4. Functional Programming 103 Functional Programming Concepts 103 How to Be Lazy 108 Lazier Than Lazy 116 Recursion Revisited 121 Wrapping Up 130 5. State 131 Concurrency, Parallelism, and Locking 132 Refs and Software Transactional Memory 133 Use Atoms for Uncoordinated, Synchronous Updates 140 Use Agents for Asynchronous Updates 141 Managing Per-Thread State with Vars 145 A Clojure Snake 150 Wrapping Up 159 6. Protocols and Datatypes 161 Programming to Abstractions 161 Interfaces 164 Protocols 165 Datatypes 169 Records 174 reify 180 Wrapping Up 181 7. Macros 182 When to Use Macros 182 Writing a Control Flow Macro 183 Making Macros Simpler 189 Taxonomy of Macros 194 Wrapping Up 202 8. Multimethods 203 Living Without Multimethods 203 Defining Multimethods 205 Moving Beyond Simple Dispatch 208 Creating Ad Hoc Taxonomies 210 When Should I Use Multimethods? 214 Wrapping Up 217 9. Java Down and Dirty 218 Exception Handling 219 Wrestling with the Integers 222 Optimizing for Performance 224 Creating Java Classes in Clojure 229 A Real-World Example 234 Wrapping Up 241 10. Building an Application 242 Scoring a Clojurebreaker Game 243 Testing the Scorer 246 test.generative 250 Creating an Interface 258 Deploying Your Code 263 Farewell 266 A1. Editor Support 267 A2. Bibliography 268 Index 269
If you want to keep up with the significant changes in this important language, you need the second edition of _Programming Clojure_. Stu and Aaron describe the modifications to the numerics system in Clojure 1.3, explain new Clojure concepts such as Protocols and Datatypes, and teach you how to think in Clojure.
The second edition of Programming Clojure is the first book to cover the new features in Clojure 1.3. Clojure experts Stuart Halloway and Aaron Bedra have updated the first book on Clojure, and new examples have been added to demonstrate the power and depth of the new features.