There is no return: the '<-' returning variable

The complete source of functions_no_return.ek9, compiled by the EK9 compiler. Shown on flowControl.html, functions.html, concepts/no-return.html.

#!ek9
defines module site.functions.noreturn

  defines constant
    noon <- 12
    evening <- 18

  defines function

    //The initial value is the answer unless a later statement replaces it.
    greeting() as pure
      -> hour as Integer
      <- rtn as String: "Good evening"

      if hour < noon
        rtn: "Good morning"
      else if hour < evening
        rtn: "Good afternoon"

    //No initial value: the compiler proves that every path gives it one.
    sign() as pure
      -> amount as Integer
      <- rtn as String?

      if amount < 0
        rtn: "negative"
      else if amount > 0
        rtn: "positive"
      else
        rtn: "zero"

    //A switch returns a value through its own '<-' variable.
    dayKind() as pure
      -> day as String
      <- rtn as String: switch day
        <- kind as String?
        case "Saturday", "Sunday"
          kind: "weekend"
        default
          kind: "weekday"

    lookup() as pure
      -> code as String
      <- rtn as String?

      if code == "GB"
        rtn: "United Kingdom"
      else
        rtn: String()

    //A guard replaces the early return: the body runs only when lookup gives a set value,
    //otherwise the initial value stands.
    countryName() as pure
      -> code as String
      <- rtn as String: "unknown"

      if name <- lookup(code)
        rtn: name

    isPositive() as pure
      -> amount as Integer
      <- rtn as Boolean: amount > 0

    //A stream replaces a loop with 'continue' or 'break': 'filter' skips items ('head n' would stop
    //early), and '>' adds each Integer into the returning variable.
    sumOfPositives() as pure
      -> amounts as List of Integer
      <- rtn as Integer: 0

      cat amounts | filter by isPositive > rtn

  defines program

    NoReturn()
      stdout <- Stdout()

      stdout.println(greeting(9))
      stdout.println(greeting(20))
      stdout.println(sign(-4))
      stdout.println(sign(0))
      stdout.println(dayKind("Sunday"))
      stdout.println(dayKind("Monday"))
      stdout.println(countryName("GB"))
      stdout.println(countryName("XX"))
      stdout.println($ sumOfPositives([-3, 0, 7, 2]))

Download functions_no_return.ek9

Output

Good morning
Good evening
negative
zero
weekend
weekday
United Kingdom
unknown
9