Nabi 0.1.3 已于 2026年11月22日 发布 →

规则清晰,
如蝶般自由。

一门编译型语言:封闭的和类型,没有 null,错误写在签名里。

$ curl -fsSL https://nabi.sh | sh

macOS(Apple 芯片)、Linux 和 FreeBSD。也可以下载压缩包。

阅读指南或在浏览器中试用

编译器替你检查什么

和类型的每一种情况

一个值的类型是 i32 | str | bool,match 就必须处理这三种情况。漏掉一种,或者以后再加一种,编译器都会指出哪种情况没有分支处理。

指南第 5 章:和类型与 none
src/main.nabi运行 ↗
fn describe(v: i32 | str | bool) -> str {
    match v {
        n: i32 => f"integer {n}",
        s: str => f"string {s}",
    }
}

fn main() {
    println(describe(true));
}
$ nabi run
   Compiling describe (.)
error[E0098]: non-exhaustive match on `bool | i32 | str`: `bool` not covered
  --> src/main.nabi:2:5
   |
 2 |     match v {
   |     ^^^^^^^^^
   |
   = help: add `x: bool => ..`
error: could not build describe (1 error, 0 warnings)
终端里的 nabi run:nabic 对这个程序的报告

可能缺失的值

没有 null。可能不存在的值,类型是 T?,值不存在时怎么办要写在代码里:用 ?? 给出默认值,或用 if let 分支处理。

指南:用 ?? 和 ?. 给出默认值
src/main.nabi运行 ↗
fn find(xs: List<i32>, target: i32) -> usize? {
    for i in 0..xs.len() {
        if xs[i] == target { return i; }
    }
    none
}

fn main() {
    let at: usize = find([70, 90], 90);
    println(at);
}
$ nabi run
   Compiling find (.)
error[E0040]: mismatched types: `let at` expects `usize`, found `usize | none`
  --> src/main.nabi:9:21
   |
 9 |     let at: usize = find([70, 90], 90);
   |                     ^^^^^^^^^^^^^^^^^^
   |
   = help: `find([70, 90], 90)` may be none: write `find([70, 90], 90) ?? 0`, or `if let x = find([70, 90], 90) { .. }`
error: could not build find (1 error, 0 warnings)
终端里的 nabi run:nabic 对这个程序的报告

看得见的错误

可能失败的函数用 throws 声明,每一处调用都要标上 try。只读代码,就能看到每一个可能出错的地方。

指南第 10 章:错误处理
src/main.nabi运行 ↗
fn parse_age(s: str) throws -> i32 {
    let n: i32 = try s.parse();
    if n < 0 { throw f"age {n} is negative"; }
    n
}

fn main() {
    let age = parse_age("-1");
    println(age);
}
$ nabi run
   Compiling ages (.)
error[E0062]: this call can throw `any Error` and must be marked with `try` (`try f()`; `try? f()` / `try! f()` to drop / panic on the error)
  --> src/main.nabi:8:15
   |
 8 |     let age = parse_age("-1");
   |               ^^^^^^^^^^^^^^^
error: could not build ages (1 error, 0 warnings)
终端里的 nabi run:nabic 对这个程序的报告

使用包

Nabi 项目发布的包随工具链一起安装:JSON 和 HTTP、表格、统计、图表等。写下 use 然后运行,nabi 就会把包加入清单,无需下载,也无需联网。注册表上的其他包,一条 nabi add <名称> 即可添加。

main.nabi
use json::parse;

let v = try parse("{\"lang\": \"nabi\", \"year\": 2026}");
println(v.get("lang")?.as_str() ?? "");
$ nabi run main.nabi
       Added json ^0.1 (official)
nabi
终端里的 nabi run:json 作为官方包被加入,然后程序输出 nabi

安装

一套工具链全包:自带代码生成器和链接器的编译器、包管理工具、REPL、Jupyter 内核、语言服务器和官方包。无需另外安装任何东西。

# macOS (Apple silicon), Linux, FreeBSD
curl -fsSL https://nabi.sh | sh

# Windows (x64, arm64), 在 PowerShell 中
powershell -ExecutionPolicy Bypass -c "irm https://nabi.sh/install.ps1 | iex"

# Nix
nix profile install github:nabi-lang/nabi
0.1.3 压缩包
macOSaarch64-apple-darwinApple 芯片.tar.xz24 MB
Windowsx86_64-pc-windows-msvcx64,Windows 11.zip70 MB
Windowsaarch64-pc-windows-msvcarm64,Windows 11.zip68 MB
Linuxx86_64-unknown-linux-gnuglibc 2.34 及以上.tar.xz26 MB
Linuxaarch64-unknown-linux-gnuglibc 2.34 及以上.tar.xz24 MB
Linuxx86_64-unknown-linux-musl静态链接,适用于任何发行版.tar.xz26 MB
Linuxaarch64-unknown-linux-musl静态链接,适用于任何发行版.tar.xz24 MB
FreeBSDx86_64-unknown-freebsdFreeBSD 14 及以上.tar.xz26 MB

校验和、其他格式和交叉编译目标:下载。

0.1.3 新特性

2026年11月22日

发布公告 完整更新日志
  • nabi audit reads nabi.lock and reports each pinned package that a packages.nabi-lang.org advisory affects, with the advisory ID, summary, severity and the version to update to (for example nabi update json). It exits 0 when nothing is affected, 1 when something is, and 2 when it cannot check, so CI can run it as a gate.
  • --json prints machine-readable output, --ignore <ID> skips an advisory, and --offline uses only the cached advisory list. The list is cached for an hour; without a network, an older cache is used with a warning. Path and git dependencies are skipped and listed as not checked.