Syntax
This page documents the shipped compiler surface. When vowplan/SYNTAX.md disagrees with an example that vow build accepts, the example wins.
Prefer the Tutorial — especially Syntax ergonomics.
Program shape
Section titled “Program shape”fn main(caps: Caps) -> int { return 0}- Top-level
functionis an alias offn(vow fmt→fn) - Methods / interface methods:
fnonly - Semicolons optional in most positions (
assertstill wants;)
Comments and literals
Section titled “Comments and literals”// line comments only (no /* block */ yet)
let n = 42let pi = 3.14let ok = truelet name = "Ada"let greeting = "line1\n\t${1 + 2}"let nums = [1, 2, 3]Bindings and assignment
Section titled “Bindings and assignment”let— immutablevar— mutable;+=-=*=/=- Parameters are immutable
- Statement-only
i++/i--
Functions, needs, contracts
Section titled “Functions, needs, contracts”fn read_poc(path: String) -> int needs FsRead { return match read_file(path) { Ok(s) => len(s), Err(_) => 0 - 1 }}
fn withdraw(balance: int, amount: int) -> int requires amount > 0 requires amount <= balance ensures result >= 0{ return balance - amount}Control flow
Section titled “Control flow”No parenthesized conditions — if a > 0, not if (a > 0). Parentheses remain for grouping.
// fragment-onlylet n = if true { 42 } else { 0 }
let area = switch s { case Circle(r): 3 * r * r, case Rect(w, h): w * h,}
let area2 = match s { Circle(r) => 3 * r * r, Rect(w, h) => w * h,}
while i < n { i += 1 if i == 3 { continue } if i == 8 { break }}
for var i = 0; i < 3; i++ { /* body */ }for i in 0..n { /* 0 <= i < n */ }for x in xs { sum = sum + x }switch desugars to match (same exhaustiveness). Boolean logic: and / or / not.
Structs, enums, constructors, inheritance
Section titled “Structs, enums, constructors, inheritance”class ≡ struct. Enums: Shape::Circle(2). Matches / switches are exhaustive.
// fragment-onlyvar c = new Counter(0) // calls Counter.new(...)Inheritance: open class / extends / mandatory override. See OOP.
Option / Result sugar
Section titled “Option / Result sugar”// fragment-onlylet d = none_i ?? 99let maybe_len = Some("abc")?.len()
let ok_val = try fallible(true) catch (e) { e }
try { let x = fallible(false)} catch (e) { print("caught err=", e)}try/catch is Result sugar, not stack-unwinding exceptions. ? propagates Err.
Regions
Section titled “Regions”region { let scratch = str_join(["a", "b", "c"], "-") print scratch}Lambdas
Section titled “Lambdas”// fragment-onlylet zs = array_map(xs, (x: int) -> x * 3)Pipe lambdas |x| are rejected.
Modules
Section titled “Modules”import utilimport vws from vow_web_serverprint / eprint
Section titled “print / eprint”// fragment-onlyprint("counter=", c.n) // preferred call formprint x // bare form still workseprint "debug:", nAmbient debug I/O (no Caps).
Canonical vs design-doc spellings
Section titled “Canonical vs design-doc spellings”| Design prose | Shipped |
|---|---|
Int / List / Float |
int / Array / f64 |
FileRead (primary) |
Prefer FsRead (FileRead is an alias) |
| ` | x |
/* */ |
// only |