Skip to content
Weaverv0.5.0

A first program

A Weaver source is a .wft file, and a program starts at its main function. Write this one to hello.wft:

import weaver.io.print
fn main() {
print("Hello, world")
}

wv run compiles it and runs it:

Terminal window
wv run hello.wft

wv build leaves a native executable, which depends on nothing but the C library:

Terminal window
wv build -o hello hello.wft

While you write, wv check reports the errors without building anything, and wv build -dev compiles without optimization, with debug information, about three times faster.

A function that can fail says so in its type: T ! E is a T, or the error E. After a call, ! hands the error to the caller and keeps the value:

import weaver.io.print
fn double(text: String): Int ! = Int.parse(text)! * 2
fn main() ! {
print("${double("21")!}")
}

An error that main lets out is printed, hello: not an integer, and the program exits with code 1. Nothing is thrown and nothing unwinds: the reference has the whole of it.

A test is a function marked @test, in the file it tests. Here is double again, with its test:

import weaver.test.assertEq
fn double(text: String): Int ! = Int.parse(text)! * 2
@test("doubles a number")
fn doubles() ! {
assertEq(double("21")!, 42)
}
Terminal window
wv test hello.wft

wv build leaves the tests out of the program.