2.6 Lists and recursion in Nix
Lesson 13 of 68 · 13:22
Up next in 5s…
About this lesson
Nix has no for loops, so lists and recursion do the work that loops do elsewhere. This lesson shows how to take lists apart with head and tail, glue them back together with ++, and set up a recursive function in a language where every file is one single expression.
In this video
builtins.length,headandtail, and the exception waiting for you on the empty list- Two syntax pitfalls: operator precedence around
++, and whyx-1is a variable name, not a subtraction - A Fibonacci function, and the
letin trick that lets a function call itself by name - Walking a list recursively with trace output, and the lazy evaluation detail that keeps it from crashing
After this lesson
You can decompose, rebuild and recurse over lists, which is exactly what the next two exercises assume you can do.