# Confusion on nil and null in test cases

**URL:** <https://forum.codecrafters.io/t/confusion-on-nil-and-null-in-test-cases/4711>\
**Category:** Challenges\
**Tags:** challenge:interpreter\
**Created:** [February 7, 2025, 9:13am UTC](https://forum.codecrafters.io/t/confusion-on-nil-and-null-in-test-cases/4711 "2025-02-07T09:13:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dyr-El](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/dyr-el/32/4800_2.png) [@Dyr-El](https://forum.codecrafters.io/u/Dyr-El)\
**Post date:** [February 7, 2025, 9:13am UTC](https://forum.codecrafters.io/t/confusion-on-nil-and-null-in-test-cases/4711/1 "2025-02-07T09:13:33Z")

</div>

For the interpreter challenge there seems to be some confusion on how to output the nil/null value.

In test case #PQ5 for the scanner it expects an output of “FUN fun null”. null is not the reserved word but possibly a lower case of the token which is called NULL in the book. I (erronously) changed my code to output null for the null object to get past the test.

But in test case #IZ6 the input is null and you expect an output of nil.

In the book the reserved keyword is nil and null as far as I can see is just an identifier, so why it should output nil in that case I cannot understand.

As the test cases stand now I need to keep track if I should use the scanner test case version of output or the evaluation output version since they are not consistent.

As far as I can make out of the book, a null or NULL in the input should never be considered as something other than a regular identifier which means at least #PQ5 is an invalid test case.

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [February 7, 2025, 7:11pm UTC](https://forum.codecrafters.io/t/confusion-on-nil-and-null-in-test-cases/4711/3 "2025-02-07T19:11:06Z")

</div>

Hi @Dyr-El, you’re right that the Lox language and its Java implementation aren’t entirely consistent.

To clarify, `null` is not part of Lox itself, but a Java primitive that the author used in his implementation.

For context, here are the author’s [test cases](https://github.com/munificent/craftinginterpreters/blob/01e6f5b8f3e5dfa65674c2f9cf4700d73ab41cf8/test/scanning/keywords.lox) for tokens with `null` in the literal field.

He had to use `null` (Java) instead of `nil` (Lox) in the Java tests, and we’re stuck with `null` even if we use other languages.

* * *

A heads-up: you will encounter [another inconsistency](https://forum.codecrafters.io/t/inconsistent-expectations-of-integers/1282) in the next stage (#lv1 Literals: Strings & Numbers). Be prepared!

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [March 10, 2025, 9:45am UTC](https://forum.codecrafters.io/t/confusion-on-nil-and-null-in-test-cases/4711/5 "2025-03-10T09:45:13Z")

</div>

Closing this thread due to inactivity. If you still need assistance, feel free to reopen or start a new discussion!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [March 15, 2025, 9:45am UTC](https://forum.codecrafters.io/t/confusion-on-nil-and-null-in-test-cases/4711/6 "2025-03-15T09:45:19Z")

</div>

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
