Skip to content

Ant is a typed language with errors as values, pipes for data, and goroutines. ​

Data flows left to right. ​

A pipe passes the value on its left as the first argument on its right. A block with x is a lambda.

ant
let result = [5, 2, 8, 1]
  | Array.filter({ x > 2 })
  | Array.map({ x * 10 })
  | Array.sort()
println(result)
txt
[50, 80]

Errors are values. ​

A function that can fail returns a Result. try hands an error up to the caller. Nothing is thrown.

ant
func load(path: string): Result[Json.Value, Error] {
  let text = try File.read(path)
  Json.parse(text)
}

let config = load("config.json")
if config is Err { println(config.error.message) }
txt
open config.json: no such file or directory

Fan out on goroutines. ​

Goroutines are cheap, and any function can start one. Parallel.map runs a function over a list on goroutines, at most limit at once, and returns when all of them are done.

ant
func slowSquare(n: int, ctx: Context): int {
  Time.sleep(100ms, ctx)
  n * n
}

let squares = Parallel.map([1, 2, 3, 4], slowSquare, limit: 3)
println(squares)
txt
[1, 4, 9, 16]

HTML is an expression. ​

Markup is a value of type Html, checked like any other expression. Text interpolated into it is escaped, so a page is safe by default.

ant
type Post = { title: string, url: string }

func link(post: Post): Html {
  <a href={post.url}>{post.title}</a>
}

let post = Post{ title: "Hello <world>", url: "/hello" }
println(<p>{link(post)}</p>)
txt
<p><a href="/hello">Hello &lt;world&gt;</a></p>

Unions of records. ​

A union lists the types a value can have. is tells which one it holds, and inside the branch its fields are there to use.

ant
type Card = { last4: string }
type Cash = { change: int }
type Payment = Card | Cash

func receipt(p: Payment): string {
  if p is Card { "card ending ${p.last4}" }
  else { "cash, ${p.change} back" }
}

println(receipt(Card{ last4: "4242" }))
println(receipt(Cash{ change: 5 }))
txt
card ending 4242
cash, 5 back

The tools come with the language. ​

One binary checks, formats, tests, and documents Ant, and teaches your editor all of it.

ant check

Type checker ​

A sound type checker: if ant check passes, the types hold when it runs. When it fails, it points at the exact characters and suggests a fix.

term
$ ant check greet.ant
greet.ant:2:13: nmae is not defined [undefined]
   │
 2 │   "Hello, ${nmae}"
   │             ^^^^
   = help: did you mean name?

1 error

ant check

Warnings ​

Some mistakes are perfectly valid code. The checker catches those too, says what goes wrong, and offers the fix.

term
$ ant check save.ant
save.ant:2:1: warning: the Result of File.write is discarded, so its Err is lost [unused-result]
   │
 2 │ File.write("report.txt", report)
   │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = help: propagate it with try, or discard it on purpose with _ = ...
   = fix: _ = ...

1 warning

ant fmt

Formatter ​

One style, with no options. Every editor formats on save.

ant
func  area(w:int,h :int):int{
w*h }
ant
func area(w: int, h: int): int {
  w * h
}

ant test

Tests ​

Tests sit beside the code they test. A failed assert prints both sides.

term
$ ant test
--- FAIL: area_test.ant: area of a strip (0.00s)
    assertion failed: area(1, 4) == 5 (4 == 5)
      at test "area of a strip" (area_test.ant:10:9)
FAIL  1 failed, 1 passed (0.00s)

ant lsp · ant dap

Your editor already knows Ant. ​

The language server brings completion, hover, go to definition, rename, and diagnostics to VS Code, IntelliJ, and Neovim. The debugger sets breakpoints and shows values.

ant code

Code queries ​

What the checker knows, on the command line: types, definitions, and references, for scripts and agents.

term
$ ant code type geo.ant:7:5
let origin: Point
$ ant code def geo.ant:8:9
geo.ant:3:6: func norm(p: Point): int
$ ant code refs geo.ant:3:6
geo.ant:8:9: println(norm(origin))
1 reference in 1 file

ant

REPL ​

Run ant on its own to try an idea, with highlighting, completion, and history.

term
$ ant
> let a = [3, 1, 2] | Array.sort()
> a
[1, 2, 3]
> "total: ${Array.sum(a)}"
total: 6

ant doc

Documentation ​

Docs for any name, in the terminal, from the standard library or your own code.

term
$ ant doc String.split
func String.split(s: string, sep: string): Array[string]

    String.split returns the pieces of s between each occurrence of sep. It panics if sep is empty.

        String.split("a,b,,c", ",")   // ["a", "b", "", "c"]
        String.split("", ",")         // [""]