Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
We wrote several higher-order functions in the last section. Specifically, our functions accepted a function as one argument and applied it to other arguments. Now we’re going to look at another kind of higher-order functions, those that create and return new functions. The ability to create functions dynamically is a crucial aspect of functional programming. In this section, we’ll focus on a functional programming technique where we’ll write functions that return new functions of less arity than the ones they accept as an argument. We’ll do this by partially applying the function, the meaning of which will become clear shortly.
Let’s imagine you have a function that accepts a tax percentage (such as 8.0 or 9.75) and a price. It returns the price by adding the appropriate tax. You can easily implement this with a threading macro: