Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying The Clojure Workshop
  • Table Of Contents Toc
  • Feedback & Rating feedback
The Clojure Workshop

The Clojure Workshop

By : Joseph Fahey , Thomas Haratyk , Scott McCaughie , Yehonathan Sharvit , Konrad Szydlo
4.3 (13)
close
close
The Clojure Workshop

The Clojure Workshop

4.3 (13)
By: Joseph Fahey , Thomas Haratyk , Scott McCaughie , Yehonathan Sharvit , Konrad Szydlo

Overview of this book

The Clojure Workshop is a step-by-step guide to Clojure and ClojureScript, designed to quickly get you up and running as a confident, knowledgeable developer. Because of the functional nature of the language, Clojure programming is quite different to what many developers will have experienced. As hosted languages, Clojure and ClojureScript can also be daunting for newcomers because of complexities in the tooling and the challenge of interacting with the host platforms. To help you overcome these barriers, this book adopts a practical approach. Every chapter is centered around building something. As you progress through the book, you will progressively develop the 'muscle memory' that will make you a productive Clojure programmer, and help you see the world through the concepts of functional programming. You will also gain familiarity with common idioms and patterns, as well as exposure to some of the most widely used libraries. Unlike many Clojure books, this Workshop will include significant coverage of both Clojure and ClojureScript. This makes it useful no matter your goal or preferred platform, and provides a fresh perspective on the hosted nature of the language. By the end of this book, you'll have the knowledge, skills and confidence to creatively tackle your own ambitious projects with Clojure and ClojureScript.
Table of Contents (17 chapters)
close
close
Lock Free Chapter
2
2. Data Types and Immutability

A Simple Lazy Sequence

To start with, let's consider the simplest possible producer of lazy sequences, the range function, which simply returns a possibly infinite series of consecutive integers. The easiest way to write this is to use iterate:

(defn iterate-range [] (iterate inc 0))

Here, iterate returns a sequence that starts with the initializer value, zero, and then continues with the result of calling inc on zero, then on the result of that and so on. Each intermediate value becomes an item in the returned lazy sequence. It works just fine:

user> (take 5 (iterate-range))
(0 1 2 3 4)

The iterate function is doing all the work. We could stop here, but we wouldn't have learned much about how lazy sequences are built. Here's a more low-level version that performs the same task. It uses the lazy-seq macro, which is the base of all lazy sequences:

user> (defn our-range [n]
        (lazy-seq
   ...
Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
The Clojure Workshop
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist download Download options font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon