E01079: 'None' does not exist in EK9 - use tri-state semantics with '?' operator

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

What went wrong

The 'None' literal does not exist in EK9.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 793 (Why does EK9 reject None and self as identifiers?)

Rationale

EK9 uses tri-state semantics instead of None/null:

  • Tony Hoare called null his "billion-dollar mistake"
  • Python's None causes AttributeError exceptions
  • EK9's tri-state model eliminates this 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 TypeName() to create unset values. Use '?' operator to check if values are set.

See also

  • E01073: 'null' not supported (same as None)
  • E01077: 'def' not supported (EK9 uses function name directly)
  • E01078: 'elif' not supported (use 'else if')
  • E01079: 'None' not supported (use tri-state semantics)
  • E01080: 'self' not supported (use 'this')
  • E01081: list comprehensions not supported (use stream pipelines)

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

Examples

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

Fails with E01079: 'None' does not exist in EK9 - use tri-state semantics with '?' operator

#!ek9
defines module error.e01079.bad

  defines function

    //None in variable assignment
    tryNoneAssignment()
      result <- None

    //None in comparison expression
    tryNoneInComparison()
      name <- String()
      isNone <- name == None

    //None assigned to return variable
    tryNoneAsReturnValue()
      <- result as String: String()
      result: None

    //None as function argument
    helperFunction()
      -> text as String
      <- rtn <- true

    tryNoneAsFunctionArgument()
      helperFunction(None)

    //None used as a variable name
    tryNoneAsVariable()
      None <- "value"

Fixed: An unset value is TypeName(), and '?' asks whether a value is set

#!ek9
defines module error.e01079.good

  defines function

    noResultYet()
      <- result as String: String()

    hasNoName()
      -> name as String
      <- rtn as Boolean: not name?

    describe()
      -> text as String
      <- rtn as String: text? <- text else "nothing"

    describeNothing()
      <- rtn as String: describe(String())

Questions and answers

These Q&A entries show E01079 and its fix: