Language:EN
Pages: 630
Rating : ⭐⭐⭐⭐⭐
Price: $10.99
Page 1 Preview
evolving environment tooling the bare repl eclipse

Evolving environment tooling the bare repl eclipse emacs table contents

Clojure Programming
by Chas Emerick, Brian Carper, and Christophe Grand

Copyright © 2012 Chas Emerick, Brian Carper, and Christophe Grand. All rights reserved. Printed in the United States of America.

Revision History for the First Edition:

2012-03-28 First release

While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information con-tained herein.

ISBN: 978-1-449-39470-7

1. Down the Rabbit Hole . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

Why Clojure?

eval
This Is Just the Beginning

46
48

84
87
89
99
103
104
105
106
111
112
113
114
114
115
117
117
122
123
130
134

iv | Table of Contents

In Summary 157

4. Concurrency and Parallelism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159

What Is a Macro?

What Macros Are Not
What Can Macros Do that Functions Cannot?

Debugging Macros 237

Macroexpansion 237

Hygiene 244

Gensyms to the Rescue 246

&env 252

&form 254

Protocols 264

Extending to Existing Types 266

Inline Implementation 281

Reusing Implementations 285

7. Multimethods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301

Multimethods Basics
Toward Hierarchies
Hierarchies
Independent Hierarchies
Making It Really Multiple!

316
317

Part III. Tools, Platform, and Projects

393
397
398
399
403
405

Table of Contents | vii

12. Design Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457 Dependency Injection 459 Strategy Pattern 462 Chain of Responsibility 463 Aspect-Oriented Programming
466 Final Thoughts 470

13. Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 471

14. Using Relational Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491

Download from Wow! eBook <www.wowebook.com>

clojure.java.jdbc

491
494
496
496
498

Prelude

498

Queries

499
500
503
503
506

Running Queries

506

Removing Boilerplate

507
509
512
512

Views

514

A Simple (JavaScript) View

514
516
_changes: Abusing CouchDB as a Message Queue 520
522
525

The “Clojure Stack”

527

The Foundation: Ring

529
529
531
532
534

Routing Requests with Compojure

535

Templating

545
546
554

557
560

Table of Contents | ix

19. Introducing Clojure into Your Workplace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577

Just the Facts… 577

(dissoc Clojure 'JVM) 583

ClojureCLR 583

Pallet 586

Avout 587

Clojure is a dynamically and strongly typed programming language hosted on the Java Virtual Machine (JVM), now in its fifth year. It has seen enthusiastic adoption by pro-grammers from a variety of backgrounds, working in essentially all problem domains. Clojure offers a compelling mix of features and characteristics applicable to solving modern programming challenges:

• Functional programming foundations, including a suite of persistent data struc-tures with performance characteristics approaching typical mutable data structures

Clojure offers a compelling practical alternative to many who strain against the limi-tations of typical programming languages and environments. We aim to demonstrate this by showing Clojure seamlessly interoperating with existing technologies, libraries, and services that many working programmers already use on a day-to-day basis. Throughout, we’ll provide a solid grounding in Clojure fundamentals, starting from places of common expertise and familiarity rather than from (often foreign) computer science first principles.

Who Is This Book For?

Engaged Java Developers

There are millions of Java developers in the world, but some fewer number are working in demanding environments solving nontrivial, often domain-specific problems. If this describes you, you’re probably always on the hunt for better tools, techniques, and practices that will boost your productivity and value to your team, organization, and community. In addition, you’re probably at least somewhat frustrated with the con-straints of Java compared to other languages, but you continue to find the JVM eco-system compelling: its process maturity, massive third-party library selection, vendor support, and large skilled workforce is hard to walk away from, no matter how shiny and appealing alternative languages are.

We will frequently compare and contrast Clojure with Java, Ruby, and Python to help you translate your existing expertise to Clojure. In such comparisons, we will always refer to the canonical implementations of these other languages:

Ruby MRI (also called CRuby)

In formulating our approach to this book, we wanted to provide a fair bit of concrete detail and practical examples that you could relate to, but stay clear of what we thought were generally unsuccessful approaches for doing so. In particular, we’ve been frus-trated in the past by books that attempted to thread the implementation of a single program or application through their pages. Such approaches seem to result in a dis-jointed narrative, as well as the dominance of a tortured “practical” example that may or may not apply or appeal to readers.

With that in mind, we split the book in two, starting with foundational, instructional narrative that occupies roughly two-thirds of the book, followed in Part IV by a number of discrete, practical examples from real-world domains. This clear segmentation of content with decidedly distinct objectives may qualify this book as a “duplex book.”(This term may have been coined by Martin Fowler in .) In any case, we can conceive of two obvious approaches to reading it.

Preface | xiii

Who’s “We”?

The founder of Snowtide (), a small software company in Western Massachusetts, Chas’s primary domain is unstructured data extraction, with a partic-ular specialty around PDF documents. He writes about Clojure, software development, entrepreneurship, and other passions at .

Brian Carper

As an independent consultant, he develops, coaches, and offers training in Clojure. He also writes about Clojure at .

xiv | Preface

The quality of this book would be far less than it is were it not for the efforts of our technical reviewers, including Sam Aaron, Antoni Batchelli, Tom Faulhaber, Chris Granger, Anthony Grimes, Phil Hagelberg, Tom Hicks, Alex Miller, William Morgan, Laurent Petit, and Dean Wampler. We’d also like to thank all of those who provided feedback and comments on the early releases and Rough Cuts of the book, both on the O’Reilly forums and via email, Twitter, and so on.

Michael Fogus and Chris Houser have inspired us in many ways large and small. One of the smaller ways was the style and presentation of the REPL interactions in their Clojure book, The Joy of Clojure, which we shamelessly copied and iterated.

To my parents, Charley and Darleen: my compulsive curiosity about how things work, my love of language and rhetoric, and my interest in business—all of these can be traced back over the years to your consistent influence. Without it, I am certain I would not have found my unique path, started a software company, or written this book, each done against all odds.

Preface | xv

—Brian Carper, February 2012
To Rich Hickey for creating Clojure and fostering such a friendly community. To this community for having brought me to higher standards.

To my coauthors, Brian and Chas: it has been a great honor to work with you. A mon professeur Daniel Goffinet, et à ses exercices improbables, qui a radicalement changé mon approche de la programmation et de l’informatique—sur ces sujets je lui suis plus redevable qu’à nul autre.

xvi | Preface

Constant width
Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Clojure Programming by Chas Emerick, Brian Carper, and Christophe Grand (O’Reilly). Copyright 2012 Chas Emerick, Brian Carper, and Christophe Grand, 978-1-449-39470-7.”

If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at .

Safari Books Online is an on-demand digital library that lets you easily search over 7,500 technology and creative reference books and videos to

O’Reilly Media has uploaded this book to the Safari Books Online service. To have full digital access to this book and others on similar topics from O’Reilly and other pub-lishers, sign up for free at .

How to Contact Us

To comment or ask technical questions about this book, send email to:

For more information about our books, courses, conferences, and news, see our website at .

You are viewing 1/3rd of the document.Purchase the document to get full access instantly

Immediately available after payment
Both online and downloadable
No strings attached
How It Works
Login account
Login Your Account
Place in cart
Add to Cart
send in the money
Make payment
Document download
Download File
img

Uploaded by : Michael Nguyen

PageId: DOC904247C