This is the home of O'Reilly's Clojure Cookbook -
Clojure Shell XSLT CSS
Clone or download
rkneufeld Merge pull request #495 from kaffein/master
Fix example for inflection
Latest commit 1b3754a May 23, 2018
Failed to load latest commit information.
.license-assignments add license assignment Mar 28, 2014
00_frontmatter add missing space Jul 31, 2016
01_primitive-data Fix example : the actual function from inflection.core 'camel-case' (… May 18, 2018
02_composite-data Clean up wording in 2.26 Feb 28, 2015
03_general-computing Formatting changes to #451. Fixes #427 Oct 11, 2016
04_local-io Fix typo in namespace alias Nov 7, 2016
05_network-io Update the MQTT recipe to follow the upstream API Change in 5.07 Apr 10, 2015
06_databases Update 6-15_traversing-indices.asciidoc Jun 9, 2015
07_webapps Clear up discrepency in 7.14 Jul 20, 2015
08_deployment-and-distribution Fix a typo in 8.6 Jul 1, 2016
09_distributed-computation Update storm homepage links. Mar 5, 2015
10_testing Merge pull request #417 from cloojure/patch-22 Jul 21, 2014
images Update figures 4.2 and 4.3 May 25, 2014
pdf/drafts Remove .DS_Store files Jan 9, 2014
script Remove $SUDO, fixes #486 Jun 9, 2016
tools adding xsl to change xref style, rebreaking book accordingly Feb 27, 2014
.gitignore Update .gitignore to ignore sibling projects Nov 25, 2013 Update May 25, 2014 Update AsciiDoc bootstrap instructions Sep 8, 2014
book-docinfo.xml Made changes to book-docinfo.xml Mar 4, 2014
book.asciidoc Correct rendering of index and colophon Mar 10, 2014 Less forceful Nov 28, 2013
colo.asciidoc otd edits Mar 3, 2014
index.asciidoc Updating bookinfo.xml file; Adding colo file; Adding colo include and… Jan 7, 2014

Clojure Cookbook

Clojure Cookbook marks Clojure's entry into O'Reilly's prestigious Cookbook Series. The book details a large number of recipes – pairs of problems and solutions – for common topics in Clojure.

Clojure Cookbook doesn't just teach you Clojure, it also shows you how to use the language and many of its common libraries. The most difficult part of mastering any language is knowing how to apply it, in an idiomatic way, to tasks that real software developers encounter every day. This is especially true of Clojure.

With code recipes that teach you how to use the language in a variety of domains, Clojure Cookbook goes beyond simply teaching Clojure syntax and semantics. It contains annotated example code with detailed analysis and explanation for hundreds of real programming tasks. You can read the book straight through to gain insights about Clojure, or use it as a reference to solve particular problems.

Exploring the Book

If you're an Emacs-wielding Clojurist, you will probably want to read this book in Emacs, too. Here is a function that "turns the page" from one recipe to the next (find and open the next recipe, close the buffer with the previous recipe).

(defun increment-clojure-cookbook ()
  "When reading the Clojure cookbook, find the next section, and
close the buffer. If the next section is a sub-directory or in
the next chapter, open Dired so you can find it manually."
  (let* ((cur (buffer-name))
	 (split-cur (split-string cur "[-_]"))
	 (chap (car split-cur))
	 (rec (car (cdr split-cur)))
	 (rec-num (string-to-number rec))
	 (next-rec-num (1+ rec-num))
	 (next-rec-s (number-to-string next-rec-num))
	 (next-rec (if (< next-rec-num 10)
		       (concat "0" next-rec-s)
	 (target (file-name-completion (concat chap "-" next-rec) "")))
      (if (equal target nil)
	  (dired (file-name-directory (buffer-file-name)))
	(find-file target))
      (kill-buffer cur))))

If you wish, you can then bind the function to a key:

(define-key adoc-mode-map (kbd "M-+") 'increment-clojure-cookbook)

Of course, this binding assumes you're using adoc-mode for reading .asciidoc files. We suggest CIDER for evaluating code interactively. Adding the following hook to your config will enable cider-mode every time you enter an AsciiDoc file. Once active, you can start a REPL and evaluate code like you would do in any regular Clojure file.

(add-hook 'adoc-mode-hook 'cider-mode)


As of Jan. 10, 2014 we are preparing the book for print. See for more info.

Building the Book

You can build a PDF/MOBI/EPUB/HTML version of the book with the asciidoc command-line utility. (You must also have the source-highlight application installed and properly configured.)


You must have the asciidoc and source-highlight command-line utilities installed and configured before attempting to build the book.

To install and configure the tools on OS X or Linux, run the included script:

$ ./script/asciidoc/


With installation and configuration complete, all that is left is to run the asciidoc command.

  • To render a single document:

    $ asciidoc -b html5 conventions.asciidoc
    # ... outputs conventions.html
  • To render the entire book:

    $ asciidoc -b html5 book.asciidoc
    # ... outputs book.html

NOTE: Rendered output is similar to the final book, but does not include O'Reilly style sheets.


To verify asciidoc files are without error/warning, run the following:

$ ./script/asciidoc/

The only output should be the file detail.

Fixing Asciidoc Warnings/Errors

The only acceptable warning is related to structure of the book sections. It's OK to ignore this one:

asciidoc: WARNING: conventions.asciidoc: line 1: section title out of sequence: expected level 1, got level 2

Please correct all others or ask for guidance if the error message is unclear. A common one is related to callouts like "<1>" at the end of a line of code.

asciidoc: WARNING: formatting-strings.asciidoc: line 57: no callouts refer to list item 1

To prevent this warning, the callout must be commented using the language appropriate comment character(s). This also keeps the code runnable in the REPL when pasted.

Clojure Example:

(defn foo [] "bar" ) <1>

requires a semicolon before the callout reference

(defn foo [] "bar" ) ; <1>

Console Example:

Username: <1>

should be

Username: #<1>

Who we are

We are Luke Vanderhart (@levand) and Ryan Neufeld (@rkneufeld), developers, authors, conference speakers and (at the moment), teachers. For this book-building adventure we will be your guides; we'll be collecting and editing your contributions, interfacing with the publisher (O'Reilly) and writing a solid chunk of the book ourselves.


Creative Commons License
This draft of Clojure Cookbook is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.

Please see the contribution guide for how this works for accepting pull requests.

Also, please note that because this is a No Derivatives license, you may not use this repository as a basis for creating your own book based on this one. Technically speaking, this book is open source in the "free as in beer" sense, rather than "free as in speech."