Skip to content

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.

fn main(caps: Caps) -> int {
return 0
}
  • Top-level function is an alias of fn (vow fmtfn)
  • Methods / interface methods: fn only
  • Semicolons optional in most positions (assert still wants ;)
// line comments only (no /* block */ yet)
let n = 42
let pi = 3.14
let ok = true
let name = "Ada"
let greeting = "line1\n\t${1 + 2}"
let nums = [1, 2, 3]
  • let — immutable
  • var — mutable; += -= *= /=
  • Parameters are immutable
  • Statement-only i++ / i--
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
}

No parenthesized conditionsif a > 0, not if (a > 0). Parentheses remain for grouping.

// fragment-only
let 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.

classstruct. Enums: Shape::Circle(2). Matches / switches are exhaustive.

// fragment-only
var c = new Counter(0) // calls Counter.new(...)

Inheritance: open class / extends / mandatory override. See OOP.

// fragment-only
let d = none_i ?? 99
let 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.

region {
let scratch = str_join(["a", "b", "c"], "-")
print scratch
}
// fragment-only
let zs = array_map(xs, (x: int) -> x * 3)

Pipe lambdas |x| are rejected.

import util
import vws from vow_web_server
// fragment-only
print("counter=", c.n) // preferred call form
print x // bare form still works
eprint "debug:", n

Ambient debug I/O (no Caps).

Design prose Shipped
Int / List / Float int / Array / f64
FileRead (primary) Prefer FsRead (FileRead is an alias)
` x
/* */ // only