Nihil

A programming language with no keywords at all

No if, no while, no return: only symbols. Nihil compiles straight to native machine code, with no libc, no linker and no virtual machine, and its compiler is written in Nihil itself.

Install

Linux on x86_64, and macOS on Apple silicon with the Xcode Command Line Tools (xcode-select --install). On Windows, use WSL. No sudo: it installs into ~/.nihil.

curl -fsSL https://nihil-lang.dev/install.sh | sh

Then:

printf '%s\n' '>> "Hello, Nihil!\n";' > hello.nihil
nihil run hello.nihil        # compile and run: Hello, Nihil!
nihil hello.nihil            # or compile into ./hello, a native executable
nihil profile hello.nihil    # run it and see where the time goes (Linux)
nihil ide                    # the IDE, in an app window

Next: Learn Nihil in fifteen short chapters, and the library reference.

Why Nihil

The name is Latin for nothing, and _ is the value that is not there.

Self-hosted

A first compiler in assembly bootstraps a second one written in Nihil, which compiles itself to a fixed point. Its runtime is assembled by Nihil's own assembler, with the same bytes as nasm.

Typed, without annotations

Types come from values and defaults, settled across several passes. Missing values are explicit optionals.

Batteries for data

Files of fixed-width records with an on-disk key index, and queries like rows.where(price > 10.0).sort(name).

Tiny native binaries

A small runtime with a garbage collector is embedded in each executable. A "hello world" is 12 KB on Linux.

A taste

A BOOL before { is an if, v : y, i { } goes over each element, : returns.

fib(n = 0) {
    n < 2 { : n; }                 // a BOOL before "{" is an if; ":" returns
    : fib(n - 1) + fib(n - 2);
}

find(v = [0], x = 0) {
    v : y, i {                     // each element of v, and its index
        y == x { : i; }
    }
    : _;                           // "_" is "no value": find returns INT?
}

>> fib(30); >> "\n";               // 832040
pos = find([5, 8, 13], 8) || -1;   // "||" takes the value, or the fallback
3 { >> pos; }                      // an INT before "{" repeats the block: 111
>> "\n";
>> 0.1 + 0.2; >> "\n";             // 0.30000000000000004
words = "  pear, apple, fig ".trim().split(", ");
>> words.sort().join(" < ") + "\n";  // apple < fig < pear

And a small table on disk, read and written by key:

PRODUCT = @[#code: INT(4); name: STRING(12); price: FLOAT(6)];   // a data model; # marks the key
FILE = "products.dat";

@{}>> FILE, PRODUCT(1, "Coffee", 12.5);    // write by key: adds it, or replaces it in place
@{}>> FILE, PRODUCT(2, "Tea", 8.0);
@{}>> FILE, PRODUCT(3, "Cake", 15.0);

p = PRODUCT @{2} FILE;                      // one record by its key (a hash index on disk)
p.price = 7.5;
@{}>> FILE, p;

rows = PRODUCT @ FILE;                      // the whole table: an ARRAY of PRODUCT
>> $rows.where(price < 13.0).sort(name);    // a query; $ turns records into table lines
>> "total: " + $rows.sum(price) + "\n";     // total: 35.0
PRODUCT @{3} FILE = _;                      // delete by key

The table is plain text, one record per line, readable in any editor.

The language at a glance

The names after a . exist only there, so they never take a name from your program.

WriteMeaning
x = 1;a variable; its type comes from the value
cond { … } || { … }if / else (cond is a BOOL)
* cond { … }while
n { … }repeat n times
xs : x, i { … }each element of an array (or byte of a text), and its index
f(a = 0, s = "") { … }a method; every parameter has a default, which gives its type
: value;return
>> x; / << x;write to standard output / read a line
x? = 5;, x || 0, x == _optionals: a value that may be missing
@ path, @>> path, text;read a file, replace it atomically
v = [0 ; *];, v[] = x;a list: an array that grows
m = {"ana": 30}a map: values by key, in memory
r? = ?f(x);, ?!a protected call: a runtime error inside gives _, and ?! its text
?{ … } || { … }a protected block: an error inside runs the block after ||
?! = "why";raise an error, which a protected call or block catches
@ "std:json.nihil";include a library that ships with the compiler

Where it runs

The compiler writes the executable by itself, one pass at a time, until the types settle.

Linux x86_64

Native ELF executables, no libc and no linker. The reference platform, with the full test suite and a fixed-point check on every change.

macOS on Apple silicon

Native executables: each program and the same runtime as on Linux are translated, instruction by instruction, to ARM64 by a translator written in Nihil. The compiler itself runs natively on the Mac, with no Python.

A web IDE, in Nihil

An editor with a color terminal, go to definition, the generated machine code one click away, a table view for record files of any size, and an agent at your side: Claude or Codex, which read the language's specification and run your programs.

Status

Nihil is open source under the MIT license. The source code is at github.com/nihillang/nihil: issues and pull requests are welcome. To follow the project or ask a question, write to [email protected].