Tern
Tern is a compiled language that is as easy to write as Python and as safe and fast as Rust. It has no references: every value is a copy, so nothing can dangle, nothing needs a garbage collector, and data races and aliasing bugs are compile errors.
struct Order:
item: str
qty: int
price: float
fn total(orders: [Order]) float:
t = 0.0
for o in orders:
t += float(o.qty) * o.price
return t
fn main():
orders = [Order("tea", 2, 3.5), Order("scone", 3, 2.25)]
parallel: # both run at once; the compiler checks for races
sum = total(orders)
biggest = orders.sort_by(fn(o) -o.qty)[0].item
print(f"total {sum}, most ordered: {biggest}")total 13.75, most ordered: sconeTern compiles to C and then to a small native binary, a WebAssembly module, or a library for iOS and Android. A JSON web API with a SQLite database is about 70 KB, and it serves more requests per second than the same app in Go or in Rust with axum.
Start here
- New to Tern? Take the Tour of Tern: thirteen short chapters, from hello world to parallel programs.
- Know Python, Go, Rust, or JavaScript? Read Coming from another language for side-by-side translations and the mistakes people make first.
- Looking something up? The language reference covers the whole language on one page; builtins and the standard library list every function.
- Got a compile error? Search for its text in the error index, or run
tern check --jsonand read thehint.
What makes Tern different
| Values, not references | b = a copies (lazily, so it's cheap). A function can only change what you pass it with &. See how memory works. |
| Safe parallelism | parallel: runs each line as a task, and parallel for spreads a loop over every core. Two tasks touching the same variable is a compile error. See parallel programming. |
| No garbage collector, no lifetimes | Values can't point at each other, so reference counting frees everything and there is nothing to annotate. |
| Batteries for services | An HTTP server, SQLite, and JSON are in the standard library. See building web apps. |
| Runs everywhere | Native binaries, WebAssembly, iOS and Android, and C libraries. |
For AI assistants
Tern is designed to be learnable by language models. Point an assistant at llms.txt or give it llms-full.txt, which contains the whole reference, grammar, standard library, and examples in one file. Compile errors carry hints for habits from other languages (def, let, &&, range(), append, None, ...), and tern check --json reports them in a form tools can read.