Usage / Tutorial 1: your first program

Tutorial 1: your first program

This tutorial gets you from “a file” to “a runnable program” with the smallest useful workflow:

  • silk check to validate code quickly
  • silk build to produce an executable
  • (optionally) silk test to run language-level tests

1) Create a minimal program#

Create hello.slk:

import { println } from "std/io";

fn main () -> int {
  println("hello from silk");
  return 0;
}

2) Check it#

silk check hello.slk

check is meant to be cheap: it answers “does this module set parse and type-check?”

3) Build and run#

silk build hello.slk -o build/hello
./build/hello

On hosted platforms, main returns a conventional process exit code (0 means success).

4) Add a tiny test (optional)#

Add this to the same file:

import { expect_equal } from "std/test";

fn add (a: int, b: int) -> int { return a + b; }

test "add returns the sum" {
  expect_equal(3, add(1, 2));
}

Run:

silk test hello.slk

Next#

Source repository · Edit this page · View Markdown