Skip to content

Syntax ergonomics

Familiar spellings that desugar to the same checked core. Full demo: tests/lang/ergonomics.vow.

Define fn new(...) -> Type on the type, then call new Type(...):

class Counter {
n: int
fn new(start: int) -> Counter {
return Counter { n: start }
}
fn inc(self) -> Counter {
self.n = self.n + 1
return self
}
}
fn main(caps: Caps) -> int {
var c = new Counter(0)
c = c.inc().inc()
return c.n
}

Literal Counter { n: 0 } still works.

// fragment-only
fn area(s: Shape) -> int {
return switch s {
case Circle(r): 3 * r * r,
case Rect(w, h): w * h,
}
}

Desugars to match — same exhaustiveness rules. match with => remains supported.

// fragment-only
fn fallible(flag: bool) -> Result<int, int> {
if flag { return Ok(42) }
return Err(9)
}
fn main(caps: Caps) -> int {
let ok_val = try fallible(true) catch (e) {
e
}
try {
let x = fallible(false)
} catch (e) {
print("caught err=", e)
assert e == 9
}
return ok_val
}

Also: ? propagates Err to the caller; ?? / ?. for Option.

// fragment-only
print("counter=", c.n)
print("opt=", unwrap_or(Some(5), 0), unwrap_or(none_i, 7))

Call form with parentheses (console.log-style). Bare print x still works. Ambient — no Caps grant.