Language Tour

Modules and more

Modules and imports

Each .vary file is a module. Directories are packages.

import math_utils
import math_utils as m
from math_utils import square, cube
from math_utils import square as sq

Names starting with _ are private and not exported. Use __all__ to explicitly control which names are importable. See Modules and imports for more.

Concurrency

spawn runs a function asynchronously and returns a Task. Call .join() to wait for the result:

def expensive(n: Int) -> Int {
    # long computation
    return n * n
}

let task = spawn expensive(12)
# do other work here
let result = task.join()
print(result)               # 144

Testing

Vary has a built-in test DSL. No imports or framework needed:

def factorial(n: Int) -> Int {
    if n <= 1 {
        return 1
    }
    return n * factorial(n - 1)
}

def divide(a: Int, b: Int) -> Float {
    return a / b
}

test "factorial computes correctly" {
    observe factorial(0) == 1
    observe factorial(5) == 120
}

test "division by zero throws" {
    observe throws { divide(1, 0) }
}

observe is the assertion keyword. It takes a boolean expression and fails the test if it evaluates to False. throws { } evaluates to True if the body raises an exception.

Run tests with vary test file.vary or vary test src/. See Testing for the full reference.

Embedded DSLs

Vary includes compiler-level support for SQL queries, testing, and HTTP exposure. These are not library imports; they are part of the grammar and participate in type checking and code generation. See Embedded DSLs for the full reference.

← Error handling