Getting Clojure
Build Your Functional Skills One Idea at a Time
by Russ Olsen
Version: P1.0 (May 2018)
Copyright 2018 The Pragmatic Programmers, LLC. This book is licensed to the individual who purchased it. We don't copy-protect it because that would limit your ability to use it for your own purposes. Please don't break this trustyou can use this across all of your devices but please do not share this copy with other members of your team, with friends, or via file sharing services. Thanks.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf and the linking g device are trademarks of The Pragmatic Programmers, LLC.
Every precaution was taken in the preparation of this book. However, the publisher assumes no responsibility for errors or omissions, or for damages that may result from the use of information (including program listings) contained herein.
About the Pragmatic Bookshelf
The Pragmatic Bookshelf is an agile publishing company. Were here because we want to improve the lives of developers. We do this by creating timely, practical titles, written by programmers for programmers.
Our Pragmatic courses, workshops, and other products can help you and your team create better software and have more fun. For more information, as well as the latest Pragmatic titles, please visit us at http://pragprog.com.
Our ebooks do not contain any Digital Restrictions Management, and have always been DRM-free. We pioneered the beta book concept, where you can purchase and read a book while its still being written, and provide feedback to the author to help make a better book for everyone. Free resources for all purchasers include source code downloads (if applicable), errata and discussion forums, all available on the book's home page at pragprog.com. Were here to make your life easier.
New Book Announcements
Want to keep up on our latest titles and announcements, and occasional special offers? Just create an account on pragprog.com (an email address and a password is all it takes) and select the checkbox to receive newsletters. You can also follow us on twitter as @pragprog.
About Ebook Formats
If you buy directly from pragprog.com, you get ebooks in all available formats for one price. You can synch your ebooks amongst all your devices (including iPhone/iPad, Android, laptops, etc.) via Dropbox. You get free updates for the life of the edition. And, of course, you can always come back and re-download your books when needed. Ebooks bought from the Amazon Kindle store are subject to Amazon's polices. Limitations in Amazon's file format may cause ebooks to display differently on different devices. For more information, please see our FAQ at pragprog.com/frequently-asked-questions/ebooks. To learn more about this book and access the free resources, go to https://pragprog.com/book/roclojure, the book's homepage.
Thanks for your continued support,
Andy Hunt
The Pragmatic Programmers
The team that produced this book includes: Andy Hunt (Publisher) Janet Furlow (VP of Operations) Brian MacDonald (Managing Editor) Jacquelyn Carter (Supervising Editor) Michael Swaine (Development Editor) Candace Cunningham (Copy Editor) Potomac Indexing, LLC (Indexing) Gilson Graphics (Layout)
For customer support, please contact .
For international rights, please contact .
To
Mikey
Felicia
Jackson
Charlie & Jennifer
Tim & Emily & Evan
Nicholas & Jonathan
Meg & Alex & Zachary
and
Scott Downie
The future is in your hands.
Table of Contents
Copyright 2018, The Pragmatic Bookshelf.
Early Praise for Getting Clojure: Build Your Functional Skills One Idea at a Time
At long last, Russ Olsen brings his engaging and encouraging style to the Clojure landscape. I wish Getting Clojure had been available when I was learning the language. If youre looking for a smooth transition into Clojure, this is it.
Ben Vandgrift |
Chief Architect, Oryx Systems Inc. |
The book was a joy to read and is highly recommended due to its comprehensive scope and brilliant writing. It also showcases the spirit of the Clojure community: a deeply knowledgeable but also informal, exploratory, no-nonsense approach to thinking about software.
Tibor Simic |
Software Developer, Inge-mark |
My favorite sections in the book: "In the Wild"code that is live and used today. Seeing real code immensely propelled my understanding of the materials, far beyond any contrived examples. I wish I had this book five years ago!
Nola Stowe |
Software Engineer, Cond Nast |
Let Russ Olsens destructuring of Clojure map mind-twisting concepts into a promise of your bright future as a capable functional coder.
Stefan Turalski |
Software Developer, BNP Paribas |
The perfect initiation into the world of Clojure.
Scott Downie |
VP Support and Services, Illumio |
Acknowledgments
If it takes a village to raise a child, it takes a community to build aprogramming language. Id like to thank Rich Hickey for creating Clojure andeveryone who has ever contributed even a little to Clojure for making myprofessional life just a bit better.
Id also like to offer my warm thanks to everyone at Cognitect, especiallyJustin Gehtland and Mike Nygard for their generous support of this book.
In the same spirit, while authors get most of the credit,behind every book stands a village of people who contributedin some way. So Id like to say thanks to JamieKite, Alex Miller, Ben Vandgrift, Nola Stowe, and Karen Cross for sufferingthrough the early drafts of this book and suggesting ways that I could turn aconfused mess into something people might read.
Special thanks to Jay Martin for his insightful commentsand toPaul deGrandis for pointing out the MAL project.
Im grateful to Jeb Beich for his patience with my amazingly stupid questions.
Id also like to thankScott Downie,Jackson Olsen,Alex Redington,Tibor Simic,Nola Stowe,Stefan Turalski,and Ben Vandgriftfor providing technical feedback as this book went to press.
Im also grateful to all the folks at The Pragmatic Bookshelf (especiallyMichael Swaine) for their help in pushing this bookout the door.
Last and certainly not least Id like to thank my lifelong partnerKaren Cross for her constant love and support and encouragement.And thanks to my son Jackson Olsen for the same and for forgivingme for making fun of The Wheel of Time . Well, mostly forgiving me.
Copyright 2018, The Pragmatic Bookshelf.
Preface
I have been writing this bookat least in my headfor decades.As a professional programmer who has used everything from assembly language andFORTRAN to C and Python and Java and Ruby, Ive spentmuch of my career longing to get myhands on a better programming language. In my minds eye I could see exactlywhat I wanted: I wanted a language that had the stripped-down syntax of Lisp.I wanted a language that embraced the power of functional programming. I wanteda language that was fast enough to run the real-world applications that I waswriting.Most of all I wanted a language that had all the above and ranon the computing platforms I worked with.For years my imaginary programming language remained just thatimaginary.I spent a lot of that time mentally composing a book that wouldlay out the case for my dream programming language.