Capabilities, not ambient power
The core language can’t do IO or allocate. A file declares uses io, alloc, and main passes the values down, so a signature shows what a function can touch.
A small language with a strict compiler: what a function may do is in its signature, and memory mistakes do not compile.
The core language can’t do IO or allocate. A file declares uses io, alloc, and main passes the values down, so a signature shows what a function can touch.
A buffer has one owner. Use after free, double free and leaks are compile errors, with no lifetime annotations.
No undefined behaviour outside allow unsafe code. Integer overflow, integer division by zero and out-of-bounds indexing panic.
Near C on most programs, with every check on, and 1.3 to 5.6 times the Rust port’s throughput on a real web app’s benchmark routes, both with caches on (numbers).
Owned values move between threads over channels; what they share is immutable (Shared(T)) or atomic, as in Erlang, so there are no locks.
Strict errors with stable codes, diagnostics as JSON (eggc check --json), and the whole spec in one command (eggc spec) to paste into a prompt.
Forget the defer, and the leak does not compile:
hello.egg:4:11: error[E135]: 'msg' still owns its buffer when 'greet' ends; free it (a.free(msg)), return it or pass it on
Drop io from uses, and neither does the capability:
hello.egg:6:8: error[E130]: 'greet' uses io (Io.print), but its module does not declare it; add `uses io` at the top of the file
Change a buffer while a slice of it is still needed:
const path = line[4..]
a.push(&line, '!') // may move the bytes
io.print(path)
slice.egg:7:12: error[E149]: 'line' cannot be changed here: the slice 'path' of it is used later
Once path is finished with, the same push is fine: a borrow ends at its last use.
uses io
const Shape = union(enum) {
circle: i64
rect: Size
empty
}
const Size = struct { w: i64, h: i64 }
fn area(s: Shape) i64 {
switch (s) {
.circle => |r| { return 3 * r * r }
.rect => |sz| { return sz.w * sz.h }
.empty => { return 0 }
}
}
fn total(shapes: []Shape) i64 {
var sum = 0
for (shapes) |s| {
sum = sum + area(s)
}
return sum
}
fn main(io: Io) void {
const shapes = [3]Shape{ Shape{ .circle = 2 }, Shape{ .rect = Size{ .w = 3, .h = 4 } }, .empty }
io.print(total(shapes[0..])) // 24
}
More in examples/, including an HTTP server with a thread pool and keep-alive, a bytecode VM and a SQLite blog.
Egg follows Zig but stays smaller: no operator overloading, implicit conversions or hidden allocation. Function signatures spell out their types; bodies may infer them. The spec has the whole language, and the design doc why.