The language thatkinda knows what you want.

Fast, without the fuss.Safe, without the worry.

Turf builds quick, efficient programs, keeps memory safe with a carefully engineered garbage collector, and reads clean enough that your time goes into the idea, not the syntax.

This downloads the standard build, without the optional AI model support (--smart).

Other platforms and versions →

hello.tr
fn main(): int {    immut name = "Turf";    printline("Hello, " + name + "!");    return 0;}

$ turf run hello.tr

Hello, Turf!

01

Why Turf

Native speed and memory safety, without having to learn an ownership calculus first. A language earns trust through guarantees it can demonstrate, not through features it can list.

  • I

    Safe by default, unsafe by declaration

    Safe Turf code cannot corrupt memory. Programmers do not write lifetimes or borrow annotations to get this; the language and its runtime carry that responsibility.

  • II

    Native performance, with costs you can read

    Turf compiles ahead of time to native code through LLVM. The cost of an operation should be predictable from the code that spells it.

  • IV

    Nothing crosses a boundary implicitly

    Visibility, imports, errors, and foreign calls are explicit where they happen. When code reaches across a boundary, the reader can see it.

  • VII

    Stability is a promise

    A public interface, once released, is not broken casually. When a change must break something, it comes with a deliberate decision and a migration path.

The other four principles are in the constitution

02

Where Turf sits

Every language picks where its safety and speed come from, and what it pays for them.

  • CGets speed from trusting the programmerPays safety
  • C++Gets speed and abstraction from templates and manual controlPays safety, and a very large language
  • RustGets safety from its type systemPays programmer effort
  • ZigGets control and simplicity by making every allocation explicitPays safety left to the programmer
  • GoGets simplicity from a runtime and a small feature setPays a runtime, and fewer language features
  • JavaGets safety and portability from a virtual machinePays startup time and memory
  • PythonGets ease from dynamic typing and an interpreterPays speed
  • TurfGets native speed and enforced safety, with effort spent on the problemPays a runtime: no borrow checker, and no targets that cannot host one

Turf aims to offer native speed and enforced safety with the programmer's effort spent on the problem, not on the memory model, with diagnostics clear enough to teach the language as you use it.

The deliberate non-goals are in the constitution

03

A tour of the language

A declaration is mut (can be reassigned) or immut. The type is written, or left out and inferred from the initializer. Conversions are explicit, with to; give ... otherwise is the conditional expression. Integer arithmetic is checked: signed overflow and division by zero panic at run time rather than wrapping.

variables.tr
fn main(): int {    mut count = 0;                       // inferred int; same as `count: guess = 0`    immut ratio: double = 7 to double / 2.0;    immut label = "turf";                // inferred string    for i in 1..6 step i += 1 {        if i % 2 == 0 { continue; }        count = count + i;    }    mut size: string = count > 5 give "big" otherwise "small";    printline(label + ": " + size + " " + (count to string));    printline(ratio to string);    return 0;}

$ turf run variables.tr

turf: big 9 3.5

04

Get started

01

Install

The installer checks the archive's SHA-256, unpacks it into ~/.turf (Windows: %LOCALAPPDATA%\turf) and adds turf to your PATH.

Linux and macOS
curl -fsSL https://turflang.org/install.sh | sh
Windows (PowerShell)
irm https://turflang.org/install.ps1 | iex

02

Create and run

turf new creates a project, turf run builds and runs it.

Terminal
$ turf new hello
Created program package 'hello' in hello/
  hello/turf.toml
  hello/src/main.tr
  hello/README.md
  hello/.vscode/extensions.json
  hello/.gitignore
$ cd hello
$ turf run
Hello, TurfLang! This is hello.

03

Supported platforms

Every platform is Tier 1: tested on every change, and a release is blocked on it.

  • Linux x86-64glibc 2.34 or newer
  • Linux arm64glibc 2.34 or newer
  • Windows x86-64native, no MSYS2
  • macOS arm64Apple Silicon only

05

One command for all of it

turf compiles single files, and in a project it reads turf.toml, fetches dependencies and drives the compiler.

Any file

turf compile
compile a file to an executable
turf run
compile to a temporary executable and run it
turf check
report every diagnostic, write no file
turf fmt
format source files
turf explain
explain an error code
turf migrate
migrate source across a language change

Project

turf new
create a project
turf build
build the project
turf test
run the project's tests
turf add
add a dependency
turf fetch
download dependencies
turf update
update git dependencies

Diagnostics are designed

Stable error codes, precise source locations, and a written explanation for every code through turf explain. The same mistake never produces a wall of follow-on errors.

Terminal
$ turf check oob.tr
oob.tr (1 error)

── error at line 4, col 18 [E001 · array error]

  Array index out of bounds!
  You tried to access 'primes[5]', but 'primes' only has 3 elements (indices 0 to 2, or -1 to -3 counting from the end).

  Hint: Array indices start at 0 and go up to size - 1; a negative index counts back from the end (-1 is the last element).

  4 │     return primes[i];
    │                  ^ Here!

  Run `turf --explain E001` for more details.

Optional help from a local model

With --smart, an error the compiler cannot fix by itself is passed to a small language model running locally through llama.cpp. No network is involved, and nothing runs on a clean compile. A suggestion is never trusted: it is applied to an isolated copy of your program and shown only if it removes the error without introducing another.

06

The standard library

Ordinary Turf source, with no privileges your code lacks. The prelude needs no import; the rest are imported by name.

  • stringsarraymath

    string search, slicing, splitting and parsing; int[] helpers; abs, min, clamp, libm functions

  • iofsos

    printing and input, reading and writing files; paths and directories; environment and arguments

  • liststackqueuemapset

    List<T>, Stack<T>, Queue<T>, Map<K, V>, Set<T>

  • jsonhttpnet

    a JSON parser and writer; an HTTP/1.1 server and request/response types; TCP sockets and DNS

  • timerandommem

    clocks and sleeping; pseudo-random numbers (not cryptographic); manual memory and Pool

  • systest

    panic, exit; assert, assert_eq, fail

Names are snake_case; an operation that can fail returns !T and never a sentinel.

Browse the modules
Esc

Type to search.