CLOJURE FOR THE BRAVE AND TRUE
learn the ultimate language and become a better programmer
CLOJURE FOR THE BRAVE AND TRUE. Copyright 2015 by Daniel Higginbotham.
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher.
Printed in USA
First printing
19 18 17 16 15 1 2 3 4 5 6 7 8 9
ISBN-10: 1-59327-591-9
ISBN-13: 978-1-59327-591-4
Publisher: William Pollock
Production Editor: Riley Hoffman
Cover Design: Beth Middleworth and Daniel and Jessica Higginbotham
Cover and Interior Illustrations: Jessica Higginbotham
Interior Design: Octopod Studios
Developmental Editors: Hayley Baker and Seph Kramer
Technical Reviewer: Alan Dipert
Copyeditor: Anne Marie Walker
Compositors: Riley Hoffman and Susan Glinert Stevens
Proofreader: Emelie Burnette
For information on distribution, translations, or bulk sales, please contact No Starch Press, Inc. directly:
No Starch Press, Inc.
245 8th Street, San Francisco, CA 94103
phone: 415.863.9900;
www.nostarch.com
Library of Congress Cataloging-in-Publication Data
Higginbotham, Daniel.
Clojure for the brave and true: learn the ultimate language and become a better programmer / by
Daniel Higginbotham.
pages cm
Includes index.
Summary: "Guide to the functional programming language Clojure. Teaches tools and techniques for writing programs in Clojure. Covers how to wield and compose Clojures core functions; use Emacs for Clojure development; write macros to modify the Clojure programming language; and use Clojures tools to simplify concurrency and parallel programming"-- Provided by publisher.
ISBN 978-1-59327-591-4 -- ISBN 1-59327-591-9
1. Clojure (Computer program language) I. Title.
QA76.73.C565H54 2015
005.133--dc23
2015014205
No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Other product and company names mentioned herein may be the trademarks of their respective owners. Rather than use a trademark symbol with every occurrence of a trademarked name, we are using the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.
The information in this book is distributed on an As Is basis, without warranty. While every precaution has been taken in the preparation of this work, neither the author nor No Starch Press, Inc. shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in it.
About the Author
Daniel Higginbotham has been a professional programmer for 11 years, half of that at McKinsey & Company, where he used Clojure to build mobile and web applications. He has also contributed to the curriculum for ClojureBridge, an organization that offers free, beginner-friendly Clojure workshops for women. Daniel blogs about life and programming at http://flyingmachinestudios.com/, and can be found on Twitter, @nonrecursive. He lives in Durham, North Carolina, with his wife and four cats.
About the Technical Reviewer
Alan Dipert first heard about Lisp when he was 10 years old. After it was described to him, he said That sounds dumb. In 2009, he learned Clojure and revised his opinion. Alan has designed and built Clojure systems, conducted Clojure trainings, and spoken at Clojure conferences. You can keep track of Alans work and recent opinions by visiting http://tailrecursion.com/~alan or by following him on Twitter, @alandipert.
For Jess
Brief Contents
Contents in Detail
Foreword
As you read this hilarious book, you will at some point experience a very serious moment. It is the moment you admit to yourself that programming is more enjoyable after knowing some Clojure. It is also the moment that your investment in this book, in money and time, comes back to youwith interest.
Humor has a certain relationship to seriousness. It is appropriate to joke about serious things, but only after the right amount of time has passed. For example, it took years for me to be able to crack a smile when I remember my favorite uncles last words: Hold my beer.
This book works in the opposite way. It points out really funny things for the right amount of time before, and perhaps even during, the serious eventthat moment you realize you enjoy programming more because of Clojure. It does this without obscuring the deep, technical aspects of Clojure programming that you will learn.
This approach is refreshing because most of the programming books Ive read are drier than a camels fart. We are fortunate that Daniel is a brilliant programmer and writer and that his wife Jess is an equally brilliant illustrator. We are especially fortunate that they both went insane and decided to write a book at exactly the same time.
Clojure is the topic of this book, but in a way itor perhaps its creator, Rich Hickeyis also one of the authors, since Clojure is the most elegant programming language ever designed. Like the concept of brunch, Clojure is so elegant that its difficult to tell anyone anything about it without somehow improving them.
Elegance is a quality regularly ascribed to many dialects in the family of programming languages known collectively as Lisp, of which Clojure is one. All Lisps descend from a set of simple and beautiful discoveries made by the mathematician John McCarthy in 1958.
Since 1958, there have been many Lisps and Lisp books. There are many more Lisps and books to come. As artifacts of the past and future, each are right for the unique combination of constraints and desires faced and fancied by their authors, in their respective times.
I find Clojure, and this particular book about it, especially right for the present. I hope you will too.
Alan Dipert
Acknowledgments
So many people helped me birth this weird baby, and I am humbled and grateful for all their support.
First, thanks to Jess, my wife, for doing the illustrations that complete this book, giving it the visual character I had hoped for. Thanks, too, for the support and for putting up with me when I was in crazy-eyed writer mode. (P.S. It feels bizarre to thank my wife via a programming books front matter.)
Thanks to my friends and colleagues at McKinsey who read early revisions and encouraged me to keep writing. Foremost among them are Pat Shaughnessy, Alex Rothenberg, Thomas Newton, Jalil Fanaian, Chris Parker, Mark Daggett, Christian Lilley, and Mike Morreale. Yall are so great; please move to Durham.
Thanks to my friend Bridget Hillyer for being a constant source of support and positivity. I always feel like you have my back, and it means a lot to me! Thanks, too, to my friend Joe Jackson, for reading, listening to me blather, and offering feedback, and for making me feel cool by gushing about this book to other people in front of me. Alan Dipert, friend, tech reviewer, and now coworker, I give thee a million thanks for your excellent technical editing and for introducing me to Clojure in the first place.
I dont know if every writer continually asks himself, Why the hell am I doing this? Is anyone even going to read it? but I certainly did. So I want to thank all the friendly folks who wrote to me and suggested edits while the initial web version of this book was being written. That positive feedback made me feel confident that I was doing something worthwhile. By the same token, thanks to everyone who bought the Leanpub version!