The shape of a function and of a class

The complete source of forAI_structure.ek9, compiled by the EK9 compiler. Shown on forAI.html.

#!ek9
defines module site.forAI.structure

  defines function

    lineTotal() as pure
      ->
        price as Float
        quantity as Integer
      <- total as Float?

      //Assign the returning variable on every path
      total: price * quantity

  defines class
    Account
      owner as String?
      balance as Float?

      default private Account()

      Account()
        ->
          owner as String
          balance as Float
        this.owner: owner
        this.balance: balance

      balanceAfter() as pure
        -> deposit as Float
        <- result as Float: balance + deposit

      default operator ?

  defines program

    Structure()
      stdout <- Stdout()
      account <- Account("Ada", 10.0)
      stdout.println($lineTotal(2.5, 3))
      stdout.println(`Ada: ${account.balanceAfter(5.0)}`)

Download forAI_structure.ek9

Output

7.5
Ada: 15.0