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.