Tycho is a systems
programming language.
Tycho compiles to native code and handles memory without a garbage collector. It’s built for parsers, interpreters, and other programs that work with lots of temporary data.
fn evens(limit: int) -> [int]:
xs := []int
for i := 0; i < limit; i += 1:
if i % 2 == 0:
push(xs, i)
return xs
fn main():
xs := evens(10)
println(str(len(xs))) # 5
This program collects the even numbers below 10 and prints how many it found. You don’t have to allocate or free the array yourself.
The compiler handles the cleanup.
You can create an array inside a function and return it without deciding who will free it. Tycho works out where the data belongs from the code. You don’t write lifetime annotations or calls to free.
The memory guide explains how this works, starting from familiar C code. There are also limits to the model, described below.
Language features.
Tycho uses indentation rather than braces to group code. Alongside functions, strings, arrays, maps, and structs, it includes:
- Enums and pattern matching. Define a fixed set of cases and handle each one explicitly.
Optionis for values that may be missing;Resultis for operations that may fail. - Generics and closures. Generics let one function work with different types. Closures let a function capture values from the surrounding code.
- Concurrency. Run tasks in parallel and pass messages between them through channels. Parallel loops can split independent work across workers.
Corelib packages cover files, text, networking, and other common tasks. You import packages by path; there’s no package manager.
The tutorial starts with small programs. For individual features and corelib packages, see the reference.
Programs written in Tycho.
I’ve used Tycho to build a Scheme interpreter, an HTTP server, and a chess engine. Their source is included so you can read the code and run them yourself.
There’s also a compiler written in Tycho. You can find timings, memory use, and how they were measured in the benchmarks.
What you give up.
Shared pointers and runtime interfaces aren’t part of Tycho. If your program relies on them, you’ll need to change its design.
I still need a full independent security audit before 1.0. Don’t use Tycho for security-critical work. C interop can also introduce memory errors; see the security policy.
Build and run a program.
Building from source needs Git, make, and a C11 compiler (GCC or Clang 15+). The platform guide has setup instructions for your system.
$ git clone https://github.com/StefanVonRanda/tycho
$ cd tycho
$ make
$ ./tychoc examples/hello.ty && ./examples/hello
built examples/hello
what is your name: Ada
hello Ada
Type Ada when the program asks for your name.
Prebuilt compilers and checksums are on the v0.9.2 release page. You’ll still need a C compiler to build your programs.
Start with the tutorial.
If you try Tycho, I’d like to hear how it goes. Open an issue if you find a bug or something the documentation doesn’t explain.