E01073: 'null' does not exist in EK9 - use tri-state semantics (unset/set) with '?' operator

Category: E01xxx Parsing and excluded constructs · Reported in phase: SYMBOL_DEFINITION · Classification: NULL_NOT_SUPPORTED · All error codes

What went wrong

The 'null' literal does not exist in EK9.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 277 (Why does AI generate null checks instead of guards in EK9?)
  • ek9 -q 146 (How do I structure functions without early return in EK9?)
  • ek9 -q 128 (Why can't I extend List or Dict in EK9?)

Rationale

EK9 replaces null with tri-state semantics:

  • Tony Hoare (inventor of null): Called it his "billion-dollar mistake"
  • Java's NullPointerException is the runtime failure null produces
  • EK9's tri-state model eliminates this entire class of bugs

[THREE STATES IN EK9]

  1. Absent - no memory allocated to hold a value (what other languages call null); EK9 is designed so that a program can never observe it - a missing Dict key gives the getOrDefault default, typically an unset object, not an absent one
  2. Unset - Object exists but has no meaningful value
  3. Set - Object exists with valid, usable value

How to fix it

Use String(), Integer(), etc. to create unset values. Use '?' operator to check if values are set. Use guards for safe access.

See also

  • E01070: 'break' not supported (use stream pipelines with 'head')
  • E01071: 'continue' not supported (use stream pipelines with 'filter')
  • E01072: 'return' not supported (use return declarations)
  • E01073: 'null' not supported (use tri-state semantics)
  • E01074: semicolons not needed (indentation-based syntax)

https://ek9.io/basics.html#tri-state https://ek9.io/forAI.json#$.excludedFeatures.features[?(@.keyword=="null")]

Examples

Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.

Fails with E01073: 'null' does not exist in EK9 - use tri-state semantics (unset/set) with '?' operator

#!ek9
defines module error.e01073.bad

  defines function

    unknownName()
      <- name as String: String()
      name: null

Fixed: An unset value stands where null would; test it with ?

#!ek9
defines module error.e01073.good

  defines function

    unknownName()
      <- name as String: String()

    greeting()
      -> name as String
      <- message as String: "Hello, guest"
      if name?
        message: "Hello, " + name

Questions and answers

These Q&A entries show E01073 and its fix: