Loading...
intermediate
Problem 09 • Step 01
Nil
Your language has three types of values:
- Numbers like
0,1,3.14. The set of possible values is infinite. - Booleans:
trueandfalse. The set has exactly two values.
Now add a third:
- Nil:
null. The set has exactly one value.
A type with one value carries no information beyond its own existence. It means “nothing here.” Not zero (that’s a number). Not false (that’s a boolean). Just… nothing.
In JavaScript, null represents nil. The match library (match-nil.js) already recognizes it and has pre-seeded the name "nil" in the environment so that evaluate("nil") returns null.
This may seem like a detour from building lists. It isn’t. You’ll need nil in a couple of steps, and when you do, the reason will be obvious.
Your job is to add the rule that handles nil in the evaluator. It follows the same pattern as numbers and booleans: nil evaluates to itself.