OxL Reference

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:

oxl✓ checked in CI
// 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
}
Output
Hello, world!
sh
oxl run hello.oxl
oxl check hello.oxl
oxl fmt hello.oxl

Everything 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#

sh
oxl new hello
cd hello
oxl run
oxl test

oxl new creates a directory with two files:

toml
# 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:

oxl✓ checked in CI
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#

See also

OxL 1.0.0-beta · Documentation version 1.0.0-beta© OxwaldLink · generated from the Standard, the std sources and the guides