Chapter 8. More on functional programming

 

This chapter covers

  • A refresher on higher-order functions
  • Partial application of functions
  • Lexical closures
  • Traditional object-oriented programming (OOP) in Clojure

So far you’ve seen a lot of the Clojure programming language, and you’ve used it to write a good number of functions. Because it’s a functional programming language, understanding and mastering the functional programming paradigm is key to being successful with it. In this chapter, we’ll explore this topic some more.

Instead of approaching this from, say, a mathematical (or plain theoretical) standpoint, we’ll review code to explore some of the main ideas. We’ll start by implementing a few common higher-order functions that you often see used in functional programs. The idea is to help you become comfortable with recursion, lazy sequences, functional abstraction, and function reuse.

Next, we’ll visit the land of partial application. This exposure will give you further insight into functional programming and what you can do with it. Although partial application doesn’t find particularly widespread use in Clojure, sometimes it’s the perfect fit for the job. Incidentally, you’ll also see the alternatives to partial application later in the chapter.

8.1. Using higher-order functions

8.2. Partial application

8.3. Closures

8.4. Summary