Getting Started

Syntax overview

Vary is a statically typed language with lightweight, brace-delimited syntax. This page shows the shape of the language at a glance. The pages that follow explain each part in detail.

Variables and built-in types

Use let for immutable values and mut for values that can be reassigned. Types are usually inferred, but can be written explicitly after a name.

let name = "Vary"
let version: Float = 0.1
mut visits = 0
visits = visits + 1

let tags: List[Str] = ["typed", "readable", "JVM"]
let scores: Dict[Str, Int] = {"Alice": 95, "Bob": 87}

The core scalar types are Int, Float, Bool, and Str. Collections use generic types such as List[Int], Dict[Str, Int], and Set[Str].

For related bindings and multi-step expressions, see readable blocks.

Functions and strings

Functions start with def. Parameter types are required; return types can be explicit or inferred. Prefix a string with f to interpolate expressions.

def greet(name: Str, loud: Bool = False) -> Str {
    let message = f"Hello, {name}!"
    if loud {
        return message.upper()
    }
    return message
}

print(greet("Ada"))

Lambdas use the same typed-parameter style:

let double = lambda x: Int: x * 2
let doubled = [double(n) for n in range(5)]

Control flow

Conditions and loops use braces rather than indentation. There are no parentheses around conditions.

for n in range(6) {
    if n % 2 == 0 {
        print(f"{n} is even")
    } else {
        print(f"{n} is odd")
    }
}

match handles literals, tuples, lists, types, and enum variants:

enum Shape {
    Circle(radius: Float)
    Rectangle(width: Float, height: Float)
    Point
}

def describe(shape: Shape) -> Str {
    match shape {
        case Shape.Circle(radius) {
            return f"circle with radius {radius}"
        }
        case Shape.Rectangle(width, height) {
            return f"rectangle {width} x {height}"
        }
        case Shape.Point {
            return "point"
        }
    }
}

For model-backed decisions, an explicit ai using context block adds if ... feels, match ... by meaning, semantic while, and llm ... using. Each semantic branch handles uncertainty separately from ordinary false or fallback outcomes. See Semantic AI control flow.

Data, classes, and interfaces

Use data for immutable values with generated equality, hashing, string conversion, and copying.

data Point {
    x: Int
    y: Int
}

let origin = Point(0, 0)
let moved = origin.copy(x=10)

Classes hold mutable state. Interfaces provide polymorphism without class inheritance.

interface Named {
    def display_name(self) -> Str {
    }
}

class User(name: Str) implements Named {
    def display_name(self) -> Str {
        return self.name
    }
}

Optionals and errors

Append ? to a type that may be None. A check narrows the value to its non-optional type inside the block.

def find_name(id: Int) -> Str? {
    if id == 1 {
        return "Ada"
    }
    return None
}

let name = find_name(1)
if name is not None {
    print(name.upper())
}

For expected failures, Result[T, E] makes success and error values explicit. Exceptions are available for exceptional failures with try, except, finally, and raise.

Contracts and tests

Contracts document and check a function's input and output rules. Tests are part of the language: observe records the behavior that must remain true, and across checks a property over generated inputs.

def withdraw(balance: Int, amount: Int) -> Int {
    in { amount > 0 }
    out (remaining) { remaining >= 0 }
    return balance - amount
}

test "withdraw subtracts the amount" {
    observe withdraw(100, 30) == 70
}

test "doubling is always even" {
    across(n: Int) {
        observe (n * 2) % 2 == 0
    }
}

Continue the language tour

PageCovers
BasicsComments, variables, types, optionals, strings
CollectionsLists, dicts, sets, comprehensions
FunctionsFunctions, lambdas, operators
Control flowIf/elif/else, while, for, match/case
Types and dataClasses, data types, interfaces, enums, generics
Error handlingContracts, try/except, Result type, defer
Modules and moreImports, concurrency, testing, embedded DSLs
← Getting started
Basics →