Programming in Clojure
Programming in Clojure
Quickly get up to speed with this modern and powerful Lisp based JVM language
About the Book
Hello, thanks for stopping by and checking out my book about the Clojure programming language. If you have any questions then please feel free to contact me and I'll try to get back to you within a reasonable time frame.
Why write this book?
After I finished writing the (printed) book "Pro Vim" for Apress Publishing, I had decided I didn't want to write another book because quite frankly it can be a bit soul destroying. You make no money from it and it takes an unbelievable amount of time and effort to write something of decent quality.
So why go through that process again?
Well, I felt it needed to be written. I've bought lots of Clojure books - both printed and self-published (either via Leanpub or other means) - and there are some great books out there, but I felt they were overly complicated and focused on things I as a beginner Clojure developer either wasn't interested in or was stuff I was never going to use (and not just me, other people I know who have read the same books would claim a similar feeling, and in some cases felt they were being spoken down to by the author).
So my aim with this book was to make it useful for people like me (at the end of the day who else are you better posed to write for than yourself). But more so, I've always held the belief that I am the lowest common denominator; i.e. if I can understand it, then anyone can.
Who's the book aimed at?
This book is aimed at anyone who has written code. Not back-end or front-end but anyone who has written code. Where ever possible I try not to assume the reader has knowlege of the same things I do, and so I aim to explain things in as simple a form as possible (again, if I can understand it, then anyone can).
This book is also useful for anyone that looked at Clojure in the past and then was put off by the idea it was too complicated. Clojure is just a programming language like any other. The fact that it looks a little different (i.e. it's a Lisp based language - I cover this in the book) doesn't mean it's difficult to learn or write.
I was worried when I first saw Clojure because of a few reasons, but the main two were: it looked complex! but when I learnt the syntax I realised how amazingly straight forward it actually is and second: the amount of parenthesis! but almost immediately after writing some Clojure code for the first time I realised how not a problem this was and in fact Lisp code can be really beautiful, concise and elegant.
Don't be fooled into thinking this is just a top level look at the language, it's not! For a small read (152 pages at last count) it goes quite deep in places where I feel it necessary, and that's in order to help you to really understand specific features within the language. Only then can you properly take advantage of these features, when you know them intimately.
What's inside?
I kick-start with what Clojure is and why you should care (many of you may have heard of it, and that it's functional but not much else). Unlike some books on the subject I don't waste pages and pages on this because quite frankly you want to get started learning Clojure syntax and how to get up and running, not learn the history of the language and where its inspirations come from (hell that's what Google's for).
I move swiftly onto data structures and the general language syntax, then to functional programming (FP) concepts. Although not critical to getting code to work, understanding FP is essential for writing concise and elegant code. I then discuss the concept of sequences, destructuring, pattern matching, polymorphism (yep, you know, that word you might have heard used a lot in Object-Oriented design).
I spend a fair amount of time on the subject of concurrency, as it's an important feature and selling point of the Clojure language. Everything from delays, promises, futures, atoms, locks, agents, refs, channels - and I aim to make understanding the when as important as the what (in the beginning, writing my first Clojure application I didn't really understand the difference between let's say an atom or a ref, or what the difference was between promises and futures? nothing I read on the internet really helped to explain it in a simple/clear way - so this was another reason I wanted to write this book).
I discuss how Namespaces work in Clojure (again, this is an underplayed important part of writing applications); I explain how you can add your own features into the language thanks to its built-in Macro system. I also look at Object-Oriented Programming techniques available in Clojure (yes Clojure aims to be a functional language, but it's not a "pure" one, and on top of that it tries to be a bit more practical in terms of real-world usage by incorporating some useful OOP concepts too).
I then look at the popular Leiningen project management tool. Explain how it all works and how to use it (you'll pretty much use it all the time so it's important to understand how it all comes together). As part of this I explain how to build a very simple "hello world" web application to help get you started with Leiningen (the idea being that web applications are a book unto itself - but learning the basics really sets you up properly for building all types of applications using Leiningen).
We'll then detour slightly from the use of a REPL (which I use for the majority of the book - as it helps make it easier to test example code I present in the book) and I'll explain how you can write and run code directly within Vim (a popular text editor - see Pro Vim if you'd like to learn more)
Finally, I show you how to create a simple command line application, just to demonstrate the diversity of the Clojure eco-system.
What's with the cover art?
Clojure to me always seemed scary from the outside? When reading some Clojure books I felt a little like I was stuck in a little dingy lost out in choppy waters and so this cover seemed to represent the mood I think a lot of people have when they come to Clojure initially.
But the specific imagery has a "hopeful" quality to it. You have the dark brooding sea below but above clear bright skys above you, signalling sunshine and warmth. The horizon also helps give a feeling of endless breadth and possibility (much like the Clojure language itself).
Sure, it's a bit of a hippy sounding explanation - but hey, it's just a picture right. What's important is the book contents. So go read it! :-)
Table of Contents
-
What is Clojure?
- Why should you care?
- The name?
- Getting started
-
Data Structures and Syntax
- List
- Vector
- Map
- Set
- Vars and Symbols
-
Functional Programming
- Immutability
- Referential transparency
- First-class functions
- Partial Application (and Currying)
- Recursive iteration
- Composability
-
Sequences
- List Comprehension
- Sequence Abstraction
- Lazy Sequences
- Destructuring
- Pattern Matching
- Polymorphism
-
Concurrency
- Retriable
- Coordinated
- Asynchronous
- Thread Safe
- Delay
- Promise
- Future
- Atom
- Lock
- Agent
- Ref
- Channels
-
Conventions
- Functions
- Macros
-
Organisation with Namespaces
- What is a namespace?
- Loading namespaced files
- Interning
-
Change the language via Macros
- Expanding all the way down
- Writing your own Macros
-
OOP
- defprotocol
- deftype
- defrecord
- Reify
-
Projects with Leiningen
- 10 second example
- Help!
- Compojure
- Templates
- Project file
- Different flavours of Compojure?
- Real world example
- Getting your code ready for deployment
- Where to next?
-
Creating Command Line Apps
- Running via Leiningen
- Running via Jar
- Running via Binary
- Understanding the CLI code
- Conclusion
-
Writing Clojure from Vim
- Rainbow Parentheses
- Sexp Mappings for Regular People
- Fireplace
- Alternatives
- Summary
Other books by this author
Authors have earned$10,052,337writing, publishing and selling on Leanpub, earning 80% royalties while saving up to 25 million pounds of CO2 and up to 46,000 trees.
Learn more about writing on Leanpub
The Leanpub 45-day 100% Happiness Guarantee
Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers), EPUB (for phones and tablets) and MOBI (for Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
Top Books
C++ Best Practices
Jason TurnerLevel up your C++, get the tools working for you, eliminate common problems, and move on to more exciting things!
Digital-First Events
Joep Piscaer and Jana BorutaThe only resource you will ever need to launch your digital events program.
Algebra-Driven Design
Sandy MaguireA how-to field guide on building leak-free abstractions and algebraically designing real-world applications.
Ansible for DevOps
Jeff GeerlingAnsible is a simple, but powerful, server and configuration management tool. Learn to use Ansible effectively, whether you manage one server—or thousands.
R Programming for Data Science
Roger D. PengThis book brings the fundamentals of R programming to you, using the same material developed as part of the industry-leading Johns Hopkins Data Science Specialization. The skills taught in this book will lay the foundation for you to begin your journey learning data science. Printed copies of this book are available through Lulu.
Continuous Delivery Pipelines
Dave FarleyThis practical handbook provides a step-by-step guide for you to get the best continuous delivery pipeline for your software.
Cloud Strategy
Gregor Hohpe“Strategy is the difference between making a wish and making it come true.” A successful migration to the cloud can transform your organization, but it shouldn’t be driven by wishes. This book tells you how to develop a sound strategy guided by frameworks and decision models without being overly abstract nor getting lost in product details.
node-opcua by example
Etienne RossignonGet the best out of node-opcua through a set of documented examples by the author himself that will allow you to create stunning OPCUA Servers or Clients.
Technical leadership and the balance with agility
Simon BrownA developer-friendly, practical and pragmatic guide to lightweight software architecture, technical leadership and the balance with agility.
Everyday Rails - RSpecによるRailsテスト入門
Junichi Ito (伊藤淳一), AKIMOTO Toshiharu, 魚振江, and Aaron SumnerRSpecを使ってRailsアプリケーションに信頼性の高いテストを書く実践的なアドバイスを提供します。詳細で丁寧な説明は本書のオリジナルコンテンツです。また、説明には実際に動かせるサンプルアプリケーションも使用します。本書は2017年版にアップデートされ、RSpec 3.6やRails 5.1といった新しい環境に対応しています!さあ、自信をもってテストできるようになりましょう!
Top Bundles
- #1
Software Architecture for Developers: Volumes 1 & 2 - Technical leadership and communication
2 Books
"Software Architecture for Developers" is a practical and pragmatic guide to modern, lightweight software architecture, specifically aimed at developers. You'll learn:The essence of software architecture.Why the software architecture role should include coding, coaching and collaboration.The things that you really need to think about before... - #2
CCIE Service Provider Ultimate Study Bundle
2 Books
Piotr Jablonski, Lukasz Bromirski, and Nick Russo have joined forces to deliver the only CCIE Service Provider training resource you'll ever need. This bundle contains a detailed and challenging collection of workbook labs, plus an extensively detailed technical reference guide. All of us have earned the CCIE Service Provider certification... - #3
Modern C++ by Nicolai Josuttis
2 Books
- #4
Django for Beginners/APIs/Professionals
3 Books
- #5
Modern Management Made Easy
3 Books
Read all three Modern Management Made Easy books. Learn to manage yourself, lead and serve others, and lead the organization. - #6
Cisco CCNA 200-301 Complet
4 Books
Ce lot comprend les quatre volumes du guide préparation à l'examen de certification Cisco CCNA 200-301. - #7
Mastering Containers
2 Books
Docker and Kubernetes are taking the world by storm! These books will get you up-to-speed fast! Docker Deep Dive is over 400 pages long, and covers all objectives on the Docker Certified Associate exam.The Kubernetes Book includes everything you need to get up and running with Kubernetes! - #8
The Python Craftsman
3 Books
The Python Craftsman series comprises The Python Apprentice, The Python Journeyman, and The Python Master. The first book is primarily suitable for for programmers with some experience of programming in another language. If you don't have any experience with programming this book may be a bit daunting. You'll be learning not just a programming... - #9
CCDE Practical Studies (All labs)
3 Books
CCDE lab - #10
Linux Administration Complet
4 Books
Ce lot comprend les quatre volumes du Guide Linux Administration :Linux Administration, Volume 1, Administration fondamentale : Guide pratique de préparation aux examens de certification LPIC 1, Linux Essentials, RHCSA et LFCS. Administration fondamentale. Introduction à Linux. Le Shell. Traitement du texte. Arborescence de fichiers. Sécurité...