Function Composition

Function composition is the operation of combining two functions so that the output of one becomes the input of the next. Mathematically, composing f and g yields a new function written (f . g)(x) = f(g(x)): apply g to x first, then apply f to the result. The composed function is itself just another function that can be passed around or composed further.

SICP demonstrates this directly using higher-order procedures. As its section on higher-order procedures explains, “Procedures that manipulate procedures are called higher-order procedures,” and it shows that “higher-order procedures can serve as powerful abstraction mechanisms, vastly increasing the expressive power of our language.” Composition is one of the most basic such manipulations: a procedure that takes two procedures and returns a new procedure applying them in sequence.

Because composed functions take and return functions, composition relies on functions being first-class values. SICP illustrates this with procedures such as average-damp and newton-transform, which “return new procedures” built from procedures passed in.

In practice, composition lets programmers build larger transformations out of small, well-understood functions without introducing intermediate variables. A data pipeline expressed as a chain of composed functions reads as a single clear flow, which is why composition is central to the functional programming style.