Book Image

Learning ClojureScript

By : W. David Jarvis, Allen Rohner
Book Image

Learning ClojureScript

By: W. David Jarvis, Allen Rohner

Overview of this book

Clojure is an expressive language that makes it possible to easily tackle complex software development challenges. Its bias toward interactive development has made it a powerful tool, enabling high developer productivity. In this book, you will first learn how to construct an interactive development experience for ClojureScript.. You will be guided through ClojureScript language concepts, looking at the basics first, then being introduced to advanced concepts such as functional programming or macro writing. After that, we elaborate on the subject of single page web applications, showcasing how to build a simple one, then covering different possible enhancements. We move on to study more advanced ClojureScript concepts, where you will be shown how to address some complex algorithmic cases. Finally, you'll learn about optional type-checking for your programs, how you can write portable code, test it, and put the advanced compilation mode of the Google Closure Compiler to good use.
Table of Contents (15 chapters)
Learning ClojureScript
About the Authors
About the Reviewer


Welcome to Learning ClojureScript!

ClojureScript is an exciting new language that leverages Clojure's familiar syntax for the JavaScript runtime. This means that ClojureScript, like JavaScript, is a tool to help you write software applications that can either run in a client-side (browser) or server-side environment. This also means that ClojureScript inherits all of the wonderful benefits of Clojure, including Lisp macros, immutable and high-performance data structures, and beautiful functional syntax.

This book aims to serve as an introduction to both the core and advanced concepts of ClojureScript development with the ultimate objective of teaching you how to build single-page web applications. Whatever your background and prior level of experience with either Clojure or ClojureScript, it is our hope that this book will prove to be an invaluable aid to you in learning how to develop ClojureScript programs for the modern web.

We've structured the book in such a way as to take you through on a soft progression. Beginning with the basics of getting your interactive environment set up, we'll take you all the way through advanced subjects such as logic programming and designing your applications to use Om, a ClojureScript wrapper for Facebook's React framework. By the end of this book, you should have a deep understanding of the complete process of developing modern single-page web apps with ClojureScript, and you should feel comfortable writing applications that you know how to configure and deploy in production environments.

What this book covers

Chapter 1, Getting Ready for ClojureScript Development, covers preparing an interactive development environment for the browser as well as some basic configuration options.

Chapter 2, ClojureScript Language Fundamentals, describes the basic syntax and building blocks of the ClojureScript language.

Chapter 3, Advanced ClojureScript Concepts, focuses on idiomatic functional programming, ClojureScript macros, and concurrent software design.

Chapter 4, Web Applications Basics with ClojureScript, covers working with the DOM, CSS, and HTML5 elements.

Chapter 5, Building Single Page Applications, teaches you how to make web applications that interact with third-party data providers, such as remote databases, OAuth providers, or embedded data stores.

Chapter 6, Building Richer Web Applications, covers more advanced topics, such as WebSockets, routing for single-page applications, and building applications using Om—a ClojureScript wrapper for React.

Chapter 7, Going Further with ClojureScript, showcases various core and third-party libraries that provide elegant and unique solutions to problems such as pattern matching, data validation, and logic solving.

Chapter 8, Bundling ClojureScript for Production, focuses on the tools that are necessary to properly package your ClojureScript libraries and applications for production usage. This chapter covers testing, compiler optimizations, and how to containerize your applications.

What you need for this book

In order to be able to run some of the example code in this book, you'll need a computer that is capable of running at least Java 6, and preferably Java 7 or 8. Oracle maintains a detailed list of hardware and software requirements for the latest versions of Java online at However, most modern laptop and desktop computers should be capable of running the latest version of Java without a problem. You'll also need a browser and an internet connection in order to download the relevant software and dependencies that are needed. For a browser, we recommend Google Chrome, but any modern web browser will do just fine.

Who this book is for

This book is for web application developers who want to benefit from the power of ClojureScript to get an agile and highly-productive development platform that targets mainly browser JavaScript.

You are not required to be fluent in Clojure, but it will be easier for you if you have a basic understanding of browser or server-side JavaScript.


In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning. Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The def statement tells us that what follows will be a definition."

A block of code is set as follows:

(ns example-code)
cljs.user=> (+ 1 1)
;; => 2

cljs.user=> (* 2 3)
;; => 6

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

(ns example-code)
cljs.user=> (+ 1 1)
;; => 2 
cljs.user=> (* 2 3)
;; => 6 
cljs.user=> (/ 9 3)
;; => 3

Any command-line input or output is written as follows:

cljs.user=> (map inc [1 2 3 4 5])
;; => (2 3 4 5 6)

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "If we check the page, we should see our Page rendered! alert logged to the console."


Warnings or important notes appear in a box like this.


Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail [email protected], and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

  1. Log in or register to our website using your e-mail address and password.

  2. Hover the mouse pointer on the SUPPORT tab at the top.

  3. Click on Code Downloads & Errata.

  4. Enter the name of the book in the Search box.

  5. Select the book for which you're looking to download the code files.

  6. Choose from the drop-down menu where you purchased this book from.

  7. Click on Code Download.

You can also download the code files by clicking on the Code Files button on the book's webpage at the Packt Publishing website. This page can be accessed by entering the book's name in the Search box. Please note that you need to be logged in to your Packt account.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows

  • Zipeg / iZip / UnRarX for Mac

  • 7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at We also have other code bundles from our rich catalog of books and videos available at Check them out!


Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to and enter the name of the book in the search field. The required information will appear under the Errata section.


Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at [email protected] with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.


If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.