I started reading The Joy of Clojure, seems like a great book and I like its example code convention. I’m documenting it here because I’ll adopt it on my blog and I want to be able to link to it. I’ll call it the joyful Clojure example code convention.

A simple piece of Clojure code looks like this:

(* 2 10)

If you run it on the REPL it looks like this:

user> (* 2 10)

The first example, it’s just the code, with no return value, the second one, shows the return value, but when you have several lines it becomes cumbersome to copy and paste:

user> (* 2 10)
user> (* 2 11)
user> (* 2 12)

The Joy of Clojure code convention solves both problems by removing the prompt and leaving return values in comments:

(* 2 10)
;=> 20
(* 2 11)
;=> 22
(* 2 12)
;=> 24

Now you can copy and paste and still have the results.

If the snippet prints something, it will also be displayed but without the arrow, like this:

(println "Hello world")
; Hello world
;=> nil

8 responses to “The joyful Clojure example code convention”

  1. fogus Avatar

    Glad you like it. :-) Thanks for reading.

    1. Pablo Avatar

      I learned Common Lisp and Scheme, I even wrote my own little Lisp interpreter, in Objective-C. But that was years ago. Nevertheless I needed a book that would go faster and I wanted to learn the proper way to do things in Clojure, not just the way it works (for example, using (seq a) instead of (not (empty? a))) so your book is exactly what I needed. I’m liking it a lot.

    2. Pablo Avatar

      Oh, one more thing… I totally understood when you say, in the book, “if you don’t know Lisp, we envy you.”. I also envy people who don’t know Lisp and get to live the thrill and exciting of learning. I wish I could temporarily remove Lisp from my head just to live that again.

  2. […] you get a prompt, like user>, but here I’m using the joyful Clojure example code convention. You can give this REPL thing a try and run any code from this post in Try […]

  3. zav Avatar

    “I started reading The Joy of Clojure, seems like a great book and I like it’s example code convention.”

    Um, it’s = it is.

    1. Pablo Avatar


    2. Eduardo Avatar

      Um… it is = its ;)

  4. Alan Avatar

    or “it has”

Leave a Reply

You may also like:

If you want to work with me or hire me? Contact me

You can follow me or connect with me:

Or get new content delivered directly to your inbox.

Join 5,043 other subscribers

I wrote a book:

Stack of copies of How to Hire and Manage Remote Teams

How to Hire and Manage Remote Teams, where I distill all the techniques I've been using to build and manage distributed teams for the past 10 years.

I write about:

announcement blogging book book review book reviews books building Sano Business C# Clojure ClojureScript Common Lisp database Debian Esperanto Git ham radio history idea Java Kubuntu Lisp management Non-Fiction OpenID programming Python Radio Society of Great Britain Rails rant re-frame release Ruby Ruby on Rails Sano science science fiction security self-help Star Trek technology Ubuntu web Windows WordPress

I've been writing for a while:


%d bloggers like this: