E01077: 'def' does not exist in EK9 - define functions by name directly

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

What went wrong

The 'def' keyword does not exist in EK9. It is reported wherever it is written: a function declaration in a 'defines function' block, a method in a class, trait or program body ('def greet(name as String)'), or a statement ('def name()').

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 786 (Which keywords from other languages are excluded from E...)

Rationale

EK9 defines functions by name directly without a keyword:

  • Cleaner syntax without visual noise
  • Function name is the first thing you see
  • Similar to method definitions in classes

How to fix it

Remove 'def' and start with the function name directly. Use -> for parameters and <- for return values: 'def greet(name as String)' becomes a declaration named 'greet()' whose body starts with '-> name as String'.

See also

  • 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/functions.html https://ek9.io/forAI.json#$.excludedFeatures.features[?(@.keyword=="def")]

Examples

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

Fails with E01077: 'def' does not exist in EK9 - define functions by name directly

#!ek9
defines module error.e01077.bad

  defines function

    def greet(name as String)
      stdout <- Stdout()
      stdout.println("Hello " + name)

Fixed: Define the function by name in a defines function block; parameters follow '->'

#!ek9
defines module error.e01077.good

  defines function

    greet()
      -> name as String
      stdout <- Stdout()
      stdout.println("Hello " + name)

Found a problem?

If EK9 reported E01077 for a program you think is valid, or did not report it where it should have, use the compiler form with the smallest program that shows it. If this page is wrong or unclear, use the documentation form. Both are at github.com/ek9lang/ek9-issues.