You're looking at the documentation for the "main" branch, click here to view the documentation for the latest stable release.

Hello, world!

For our first program, we'll start off simple by printing "Hello, world!" to the terminal. Create a file called hello.inko with the following contents:

import std.stdio (Stdout)

class async Main {
  fn async main {
    Stdout.new.print('Hello, world!')
  }
}

To run the program, run the following command in your terminal:

inko run hello.inko

If all went well, the output is "Hello, world!".

Explanation

Let's explore what the program does. We first encounter the following line:

import std.stdio (Stdout)

This imports the Stdout type, used for writing text to the terminal's standard output stream. After the import we encounter the following:

class async Main {
  fn async main {

  }
}

Inko uses lightweight processes (which we'll cover separately), which are defined using the syntax class async NAME { ... }. The main process is always called "Main", and is required to define an "async" instance method called "main".

The final line writes the message to STDOUT:

Stdout.new.print('Hello, world!')

Stdout.new creates a new instance of the Stdout type, and print(...) prints the message to the standard output stream.