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),
}
}The mut keyword makes mutation explicit for mutable bindings, references, and methods that can modify their receiver in place.
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)}