Nix 101 Course / Section 2: The Nix language
Premium

2.5 Lazy evaluation explained: why 1/0 doesn't crash

Lesson 12 of 68 · 7:42

placeholder thumbnail

Sign in, then buy this course to watch

Free account · no credit card needed

About this lesson

x = 1 / 0, and evaluation succeeds? Lazy evaluation is the part of the Nix language that feels strangest to newcomers. It also explains 90% of the "wait, why didn't that fail?" moments you will ever have with Nix.

In this video

  • The division by zero puzzle: a snippet that should crash in three places, but prints "all good"
  • Using traces to prove which parts of your code Nix never even looked at
  • Rebuilding the same behavior in Python, so you see laziness in a language you already know
  • A step by step drawing of what Nix builds in memory instead of running your code
  • Why this mechanism lets you import a repository of 100,000 packages in milliseconds

After this lesson

Laziness stops being spooky. You can predict what gets evaluated and when, and that is the skill behind reading any nontrivial Nix code.