Simple, readable and fast.

Koji is a statically typed language, compiled to machine code by a compiler written in Koji. Errors are values, numbers are exact, and the code says what it does.

Get startedDownload 0.1.0

Koji 0.1.0 is a preview: try it, and tell us what is missing or wrong. Expect breaking changes before 1.0.

import http
import task

type Shape = {
    Circle(radius: decimal)
    Square(side: decimal)
}

function area(shape: Shape): decimal {
    return match (shape) {
        Circle(radius) => 3.14 * radius * radius
        Square(side) => side * side
    }
}

// Errors are values: `?` passes them on.
function half(text: string): Result[int, ParseError] {
    immut n = int(text)?
    return Ok(n / 2)
}

print(area(Circle(2)), area(Square(1.5)), 0.1 + 0.2) // 12.56 2.25 0.3
print(half('42'), half('x')) // Ok(21) Err(InvalidNumber('x'))

// Requests at the same time, on one thread.
immut pages = task.all([
    () => http.get('https://example.com'),
    () => http.get('https://example.org'),
])

Errors are values

No exceptions and no null: a function that can fail returns a Result, and ? passes the error on. match checks that every case is handled.

Exact numbers

A number with a point is a decimal, so 0.1 + 0.2 is 0.3. Integers do not overflow silently, and float is there when you want the hardware's.

Values, not references

Assigning a list gives a copy, made only when one of them changes. Files and sockets are closed when their owner goes away: no garbage collector, no defer.

Tasks without async

Tasks run ordinary code, in groups that wait for them, with channels and shared values. No call blocks the others, and a task that computes is preempted.

A compiler of its own

kojic writes machine code for x86-64 and arm64 and links it with its own linker. Building Koji needs nothing but gzip: no C compiler, no LLVM.

A useful standard library

HTTP with TLS 1.3 written in Koji, JSON, regular expressions, files, processes, dates, a command line parser, and kojic test for tests next to the code.

Try it

Download the package of your platform, unpack it and run a program:

tar -xzf koji-0.1.0-linux-x64.tar.gz
export PATH=$PWD/koji-0.1.0-linux-x64:$PATH
kojic run hello.kj

Packages for Linux, macOS and Windows are on the download page; the documentation covers the language and its standard library. For Visual Studio Code, install the extension Koji.