Why can EK9 programs only return Integer?
← Syntax and Structure Rules · Ref: Q888
EK9 programs can only return Integer (or nothing). The return value becomes the process exit code, which the operating system uses to determine success or failure.
EXIT CODE CONVENTION
0 — success 1 — general error 2 — usage error Non-zero — failure
CORRECT PATTERNS
MyProgram()
<- exitCode as Integer: 0 // Returns exit code
MyProgram()
... body ... // No return (implicit 0)
INCORRECT PATTERNS
MyProgram()
<- message as String: "done" // ERROR: E07590
MyProgram()
<- success as Boolean: true // ERROR: E07590
WHY ENFORCED
The OS can only receive integer exit codes. Returning Float, Boolean, or custom types has no meaning at the OS level. EK9 makes this explicit rather than silently discarding non-integer values.
See Q871 for hello world. See Q872 for program variables.
Example
defines module qa.syntaxrules.programreturn defines program ProgramReturnIntegerDemo() <- exitCode as Integer: 0 stdout <- Stdout() stdout.println("Program running successfully") stdout.println(`Exit code will be: ${exitCode}`)
Common mistakes
E07590 — Programs can only return Integer because the return value is the process exit code. Float, Boolean, String, and custom types cannot be used as exit codes. See ek9 -h E07590 for details.
Incorrect:
<- exitCode as Float: 0.0
Correct:
<- exitCode as Integer: 0
Other ways to ask this
- What triggers E07590 PROGRAM_CAN_ONLY_RETURN_INTEGER?
- Why can't my program return a String or Boolean?
- How do exit codes work in EK9 programs?
Coming from another language?
Java: main returns void, exit code via System.exit(int). C: main returns int (exit code). Python: sys.exit(int) or implicit 0. Go: os.Exit(int). Rust: main returns () or Result. EK9: program return type restricted to Integer at compile time.
Keywords: point, main, process, entry, exit, Integer, code, E07590, return, program