Nabi 0.1.3 已於 2026年11月22日 發布 →
規則清晰,
規則清晰,
如蝶般自由。
一種編譯式語言:封閉的和型別,沒有 null,錯誤寫在簽章裡。
編譯器替你檢查什麼
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)
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)
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 專案發布的套件會隨工具鏈一併安裝: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
數獨求解器在固定長度陣列的盤面上用回溯法解數獨,在每個空格依序嘗試每個候選數字。生命遊戲在邊緣首尾相接的 10×8 環面格子上執行 Conway 的生命遊戲,並以文字印出幾個世代。小型 Lisp 直譯器建立一個小型 Lisp:包含語彙分析器、遞迴下降剖析器,以及攜帶環境的求值器,支援 define、if、lambda 和閉包,並透過 throws 回報執行時的錯誤。TCP echo 伺服器一個程式在空閒的 127.0.0.1 連接埠上啟動 echo 伺服器,讓用戶端送出幾行文字並讀回回音,最後乾淨地關閉一切。文字冒險一個小型文字冒險遊戲,有房間、出口、物品和一扇上鎖的門,依照預先寫好的指令清單一路玩到結局。CSV 報表把一份小型銷售 CSV 寫入暫存檔,再逐行讀回,並印出欄位對齊的各地區摘要表。字數統計計算一段文字的行數、單字數與字元數,再用 Dict 和排序挑出出現次數最多的五個單字。JSON 剖析器以列舉表示 JSON 值,搭配一個以 throws 回報錯誤位置、逐字元處理的遞迴下降剖析器,以及一個會縮排的美化輸出器。
安裝
一套工具鏈全包:內建程式碼產生器與連結器的編譯器、套件工具、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| macOS | aarch64-apple-darwin | Apple 晶片 | .tar.xz24 MB |
|---|---|---|---|
| Windows | x86_64-pc-windows-msvc | x64,Windows 11 | .zip70 MB |
| Windows | aarch64-pc-windows-msvc | arm64,Windows 11 | .zip68 MB |
| Linux | x86_64-unknown-linux-gnu | glibc 2.34 以上 | .tar.xz26 MB |
| Linux | aarch64-unknown-linux-gnu | glibc 2.34 以上 | .tar.xz24 MB |
| Linux | x86_64-unknown-linux-musl | 靜態連結,適用於任何發行版 | .tar.xz26 MB |
| Linux | aarch64-unknown-linux-musl | 靜態連結,適用於任何發行版 | .tar.xz24 MB |
| FreeBSD | x86_64-unknown-freebsd | FreeBSD 14 以上 | .tar.xz26 MB |
校驗和、其他格式與交叉編譯目標:下載。
nabi auditreadsnabi.lockand 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 examplenabi 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.--jsonprints machine-readable output,--ignore <ID>skips an advisory, and--offlineuses 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.