Skip to content

Language reference ​

The language reference has one page for each keyword, operator, literal, and built-in type, and for each rule of how source text is read. This page lists them all, one line each. The functions of the standard library are in the library reference.

A few principles run through every page:

  • Every construct is an expression with a type. if and blocks give values; a statement is an expression whose value is void.
  • No value changes type without a visible conversion. A condition is a bool, and numbers of two types never mix.
  • Errors are values: a Result carries an expected failure and null carries absence. A panic is for bugs.
  • When two constructs would do the same job, the language keeps one.
ant
let n = 7
let parity = if n % 2 == 0 { "even" } else { "odd" }
parity           // "odd"
float64(n) / 2.0 // 3.5
let name: string | null = null
name ?? "anonymous" // "anonymous"

Lexical structure ​

Source files are UTF-8 text with the extension .ant.

Literals ​

Keywords ​

Declarations ​

  • let: a binding that keeps its value, and record and array destructuring.
  • var: a binding that can be assigned again, with the same destructuring as let.
  • func: a named function, an anonymous function, or a function on a type.
  • type: a record type, a named primitive type, or an alias, and type(T), a type as a value.
  • interface: a named set of function signatures that a type satisfies.
  • import: the exports of another module, as names or as a namespace.
  • export: a top-level declaration of a library that other modules can import.
  • test: a test or subtest in a test file, which ant test runs.

Control flow ​

  • if and else: one of two branches by a bool, as an expression.
  • for and in: a block for each element of an array, map, set, string, Bytes, or sequence.
  • while: a block as long as a condition is true.
  • break: ends the innermost loop.
  • continue: starts the next iteration of the innermost loop.
  • return: leaves the innermost function, lambda, script body, or go or defer block early, with a value or none.

Errors and concurrency ​

  • try: unwraps a Result, or returns its error from the function.
  • defer: a block that runs when the enclosing block exits.
  • go: runs a block on a new goroutine.
  • select: waits for the first of several blocking calls that can proceed.

true, false, and null are under Literals, is under Operators, and void under Built-in types. panic, assert, len, println, and the conversions such as float64(n) are prelude functions, in the library reference.

Operators ​

Bitwise operations are functions of the Bits namespace, not operators.

Built-in types ​

  • bool: true and false.
  • int and the sized integers: int, and int8 to int64 and uint8 to uint64.
  • byte: another name for uint8, the element of Bytes.
  • float32 and float64: IEEE 754 floating-point numbers.
  • string: immutable Unicode text.
  • void: the type and value of code that runs for its effect.
  • never: the type of an expression that does not finish.
  • Array: Array[T], an ordered, growable list.
  • Map: Map[K, V], a hash map in insertion order.
  • Set: Set[T], distinct values in insertion order.
  • Function types: func(A, B): R.
  • Self: the type that satisfies an interface, in its signatures.

null is the type of null. Bytes is built in for binary data. Records, unions, and generics have chapters of their own in the guide: Records, Unions, and Generics.

At run time ​