Hello world and the first package
A single file#
An OxL program is one .oxl file or a package. A file with a main function runs directly:
// hello.oxl
fn main() io { // io is an effect: the function writes to stdout
let name = env("OXL_DEMO_NAME") ?? "world" // env returns str?; ?? supplies a value on none
print("Hello, {name}!") // {name} is string interpolation
}Hello, world!
oxl run hello.oxl
oxl check hello.oxl
oxl fmt hello.oxlEverything that makes a function impure is visible in its signature: io, net, time, db, fs, and so on. A function
without effects is marked pure. The compiler does not let you call an io function from a pure one (§6.2,
diagnostic effects).
A package#
oxl new hello
cd hello
oxl run
oxl testoxl new creates a directory with two files:
# oxl.toml
[package]
name = "hello"
version = "0.1.0"
edition = "2027"and src/main.oxl, the root module of the package; its main is the entry point (§2.4). Other modules are
directories under src/; use imports them and the modules of the standard library (use std.io { File }). The manifest is
described in the oxl.toml format.
Tests live next to the code:
fn add(a: i32, b: i32) -> i32 pure => a + b
test "add sums two numbers" {
assert add(2, 3) == 5
assert_eq(add(-2, 2), 0)
}oxl test runs every test declaration of the package; the kinds of test (unit, integ, sim) and the filters are in the
testing tour.
Next#
- The tour of the language: types, errors, concurrency, services, actors, sagas, storage, cluster, tests, deployment.
- Examples: complete projects to download and run.
- Editor setup: highlighting, completion, debugger.