2.7 Exercise: sum a list with recursion
Lesson 14 of 68 · 5:42
Up next in 5s…
About this lesson
Time to write your first recursive Nix function yourself. The task: a sum function that takes a list of numbers and returns their total. No loops, no mutation, just recursion. It sounds small, and that is the point: this is the pattern behind real Nix code everywhere.
In this video
- The exact task and test cases, including what
sumof an empty list should return - The only hints you need:
head,tail, and checking for the empty list first - A pause point to solve it on your own before the walkthrough begins
- A trace added to the finished function so you can watch the numbers add up, call by call
After this lesson
Once you have written this function with your own hands, the recursion pattern stops being theory and becomes something your fingers know.
Links: