Confusion on nil and null in test cases

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.

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 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 in the next stage (#lv1 Literals: Strings & Numbers). Be prepared!

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