Programming Clojure

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

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 higherClojure 1.9

Author(s): Alex Miller; Stuart Halloway; Aaron Bedra
Edition: Paperback
Publisher: Pragmatic Bookshelf
Year: 2017

Language: English
Pages: 0

Acknowledgments......Page 10
Introduction......Page 11
Who This Book Is For......Page 12
What’s in This Book......Page 13
How to Read This Book......Page 15
Notation Conventions......Page 17
Web Resources and Feedback......Page 19
Downloading Sample Code......Page 20
1. Getting Started......Page 21
Simplicity and Power in Action......Page 22
Clojure Coding Quick Start......Page 31
Navigating Clojure Libraries......Page 37
Wrapping Up......Page 41
2. Exploring Clojure......Page 42
Reading Clojure......Page 43
Functions......Page 50
Vars, Bindings, and Namespaces......Page 56
Metadata......Page 63
Calling Java......Page 65
Comments......Page 69
Flow Control......Page 70
Where’s My for Loop?......Page 74
Wrapping Up......Page 78
3. Unifying Data with Sequences......Page 79
Everything Is a Sequence......Page 81
Using the Sequence Library......Page 86
Lazy and Infinite Sequences......Page 96
Clojure Makes Java Seq-able......Page 99
Calling Structure-Specific Functions......Page 105
Wrapping Up......Page 114
4. Functional Programming......Page 115
Functional Programming Concepts......Page 116
How to Be Lazy......Page 121
Lazier Than Lazy......Page 130
Recursion Revisited......Page 136
Eager Transformations......Page 146
Wrapping Up......Page 151
5. Specifications......Page 152
Defining Specs......Page 155
Validating Data......Page 157
Validating Functions......Page 165
Generative Function Testing......Page 173
Wrapping Up......Page 178
6. State and Concurrency......Page 179
Concurrency, Parallelism, and Locking......Page 180
Refs and Software Transactional Memory......Page 182
Use Atoms for Uncoordinated, Synchronous Updates......Page 189
Use Agents for Asynchronous Updates......Page 191
Managing Per-Thread State with Vars......Page 197
A Clojure Snake......Page 202
Wrapping Up......Page 213
7. Protocols and Datatypes......Page 214
Programming to Abstractions......Page 215
Interfaces......Page 219
Protocols......Page 221
Datatypes......Page 226
Records......Page 232
reify......Page 238
Wrapping Up......Page 239
8. Macros......Page 240
When to Use Macros......Page 241
Writing a Control Flow Macro......Page 242
Making Macros Simpler......Page 249
Taxonomy of Macros......Page 255
Wrapping Up......Page 265
9. Multimethods......Page 266
Living Without Multimethods......Page 267
Defining Multimethods......Page 270
Moving Beyond Simple Dispatch......Page 274
Creating Ad Hoc Taxonomies......Page 276
When Should I Use Multimethods?......Page 281
Wrapping Up......Page 285
10. Java Interop......Page 286
Creating Java Objects in Clojure......Page 287
Calling Clojure From Java......Page 292
Exception Handling......Page 293
Optimizing for Performance......Page 298
A Real-World Example......Page 308
Wrapping Up......Page 312
11. Building an Application......Page 313
Getting Started......Page 314
Developing the Game Loop......Page 315
Representing Progress......Page 317
Implementing Players......Page 319
Interactive Play......Page 323
Documenting and Testing Your Game......Page 327
Farewell......Page 332
Bibliography......Page 333