Chapter 2. Clojure elements: Data structures and functions

 

This chapter covers

  • Clojure’s core data structures
  • Clojure functions
  • Program flow with Clojure

In the previous chapter, you read about some features of the Clojure language that make it interesting. You saw some code, but it probably looked a little alien. It’s now time to set that right. This chapter and the next address the basics of writing code in Clojure. This one will give an overview of the various data structures that make up the core of the language and walk you through the fundamentals of the structure and flow of Clojure programs. By the end of the next chapter, you’ll be able to read most Clojure code and write your own programs.

2.1. Coding at the REPL

Unlike many other languages, Clojure doesn’t have to be typed into files and compiled all at once. Instead, you can interactively build a working program an expression at a time and try out code immediately. This form of interactive development is possible through the read-evaluate-print loop (REPL). It’s an interactive shell similar to those provided by languages such as Ruby and Python. In this section we’ll introduce you to interacting with a live Clojure environment through the REPL, which will enable you to follow along with the lessons in this chapter and the next. We encourage you to read these chapters near a REPL, copy the examples, explore different approaches, and try some code of your own and see what happens.

2.2. Clojure data structures

2.3. Program structure

2.4. Program flow

2.5. Summary