← Recursion · guided lesson

Recursion

1 / 18 · story

the story

Recursion

Every tool here exists because something was too slow or broke without it. Here is what.

1960 · John McCarthy (Lisp); the ALGOL 60 committee, report edited by Peter Naur

Recursion was a mathematical idea first; 1960 is when two landmark languages built it in. In April 1960, McCarthy's Lisp paper built a whole language around recursive functions. One month later, the ALGOL 60 report allowed a procedure to call itself — through one short sentence added late, after a phone call to its editor, Peter Naur. In Naur's memory the caller was van Wijngaarden, "speaking also for" Dijkstra; in Dijkstra's, it was Dijkstra himself. Maarten van Emden later retold both versions. Almost every language since, Java included, lets a method call itself.

the problem it solved

Writing code for nested, self-similar data — expressions, lists of lists, trees — in the same shape as the data.

why it matters: without it

Nested data would need a hand-managed stack everywhere; a 5-line tree method becomes 25 lines of bookkeeping.

sources: McCarthy — Recursive Functions of Symbolic Expressions and Their Computation by Machine, Part I (CACM, 1960) ↗ · Report on the Algorithmic Language ALGOL 60 (CACM, May 1960) ↗ · Maarten van Emden — How recursion got into programming: a tale of intrigue, betrayal, and advanced programming-language semantics (2014) ↗

also in this chapter: The call stack · Memoization · Quadtree