Course of Raku / Functional, concurrent, reactive, and web programming / Functional programming

Recursion

This part of the course steps beyond the everyday and looks at four powerful styles of programming that Raku supports especially well: functional, concurrent, reactive, and web programming.

We begin with functional programming — a style built around subroutines that take and return other subroutines, values that are computed only when needed, and expressions rather than step-by-step statements. The first idea is recursion: a subroutine that calls itself.

A recursive subroutine solves a problem by reducing it to a smaller version of the same problem, until the problem becomes small enough to answer directly. Counting down, walking a tree, computing a factorial — all are naturally recursive. This section shows how to write a recursive subroutine and, just as importantly, how to stop it.

Topics in this section

Practice

Complete the quizzes that cover the contents of this section.

Exercises

This section contains 3 exercises. Examine all the topics of this section before doing the coding practice.

  1. Power
  2. Sum of digits
  3. Count up

Course navigation

Functional programming   |   A recursive subroutine