Optional values
Optional values use T? rather than nil, pointers, or zero values. The absent case must be handled before the value can be used.
let user: User? = find_user(id)
let name = user
.map(fn(u) { u.name })
.or(“guest”)Ard is a general-purpose programming language with static typing, errors as values, and explicit mutable data access.
Ard is usable today, but it is still evolving and breaking changes are possible.
use go:fmt
fn fib(n: Int) Int { match n <= 1 { true => n, false => fib(n - 2) + fib(n - 1), }}
fn main() { for n in 20 { fmt::Println("fib({n}) = {fib(n)}") }}Ard has dedicated syntax for optional values, recoverable errors, and mutable data access.
Optional values use T? rather than nil, pointers, or zero values. The absent case must be handled before the value can be used.
let user: User? = find_user(id)
let name = user
.map(fn(u) { u.name })
.or(“guest”)Functions that can fail return Results (Val!Err). Callers can handle the error where recovery is possible or propagate it with try.
fn divide(a: Int, b: Int) Int!Str {
match b == 0 {
true => Result::err(“division by zero”),
false => Result::ok(a / b),
}
}mut name = expression declares a writable binding slot; mut expression creates or copies a reference value; and mut T describes a reference type.
impl Board {
fn mut play(player: Str, pos: Int) {
self.cells.set(pos, player)
}
}Ard programs use Go’s robust runtime and standard library, with cross-platform support and performance suitable for general application development. Go packages can also be imported directly.
Read about Go interoperabilityuse go:net/http as httpuse go:fmt
fn main() { let response = http::Get( "https://ard-lang.dev" ).expect("request") fmt::Println(response.Status)}