Repository navigation
Koji 0.1.0
Pre-releaseThe first release of Koji, a statically typed language that aims to be simple, readable and
fast, compiled to machine code by a compiler written in Koji. It 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'),
])
Getting it
Download the package of your platform below, unpack it and put its directory on your PATH:
| Platform | Package |
|---|---|
| Linux, x86-64 | koji-0.1.0-linux-x64.tar.gz |
| Linux, arm64 | koji-0.1.0-linux-arm64.tar.gz |
| macOS, Apple silicon | koji-0.1.0-macos-arm64.tar.gz |
| macOS, Intel | koji-0.1.0-macos-x64.tar.gz |
| Windows, x86-64 | koji-0.1.0-windows-x64.zip |
tar -xzf koji-0.1.0-linux-x64.tar.gz
export PATH=$PWD/koji-0.1.0-linux-x64:$PATH
kojic run hello.kjSHA256SUMS has the checksums of the packages. On macOS, a downloaded kojic is quarantined:
xattr -d com.apple.quarantine koji-0.1.0-macos-arm64/kojic lets it run. Koji also builds from
its repository with nothing but gzip (bootstrap/build.sh, or bootstrap\build.cmd on Windows):
see Getting Started.
The language
- Strong, static typing with inference:
int,float,decimal(exact, the default of
literals with a point),string,char,byte,boolean, lists, maps, sets, records and
sum types. matchwith guards and exhaustiveness,ifas an expression, nonull(Option), errors as
values (Resultand?), panics for bugs, no exceptions.- Value semantics with copy-on-write, move-only types with
drop,mutandtakeparameters. - Generics with the
equatableandorderableconstraints, methods, closures that capture a copy. - Modules with mandatory
export, opaque types, packages from repositories of git (koji.mod,
koji.sum, minimal version selection). - Tasks in groups, channels and shared values, on one thread; no call blocks the other tasks,
and a task that computes is preempted. testblocks andkojic test;foreignblocks for the functions of libraries of the system.
The standard library
cli, datetime, file, hash, http (a client with TLS 1.3 written in Koji, and a server),
json, math, path, regex, system (programs run with an input, a directory and an
environment), task and time.
The compiler
kojicis written in Koji and builds itself from a seed of its own executables: building
Koji needs no C compiler, no Rust, nothing butgzip. Its own tests are written in Koji too.- It generates machine code itself (x86-64 and arm64) and links executables with its own linker
(ELF, Mach-O and PE), the shared libraries offoreignblocks included on Linux and Windows. kojic run,build,check,test,lsp(a language server),init,add,update,
version. A VS Code extension gives the
highlighting and the language server; the TextMate grammar is ineditors/textmate/.
Platforms
| Platform | Tested |
|---|---|
| Linux, x86-64 | the whole test suite, in CI |
| Linux, arm64 | the whole test suite, in CI |
| macOS, arm64 and x86-64 | the whole test suite, in CI (macOS 15) |
| Windows, x86-64 | the programs of the test suite, in CI (Windows Server 2022), and under Wine |
Known limits
- Tasks run on one thread.
regexhas no look-around.- The parameters of an anonymous function given to a generic method (
.mapErr((e) => ...))
need their type written. - On macOS, the libraries of
foreignblocks are linked by the linker of the system. - The code is about 1.3 times as slow as C compiled by gcc (measured on the compiler itself).
Feedback
Issues and ideas are welcome at https://github.com/koji-language/koji/issues.