Tutorial 1: your first program
This tutorial gets you from “a file” to “a runnable program” with the smallest useful workflow:
silk checkto validate code quicklysilk buildto produce an executable- (optionally)
silk testto 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#
- More workflows: CLI examples
- Tutorial 2: Structs and
impl
Source repository · Edit this page · View Markdown