Nabi 0.1.3 출시, 2026년 11월 22일 →
규칙은 분명하게,
규칙은 분명하게,
나비처럼 자유롭게.
닫힌 합 타입, null 없음, 시그니처에 드러나는 에러를 갖춘 컴파일 언어.
컴파일러가 대신 확인하는 것
합 타입의 모든 경우
값이 i32 | str | bool이면 match는 셋을 모두 다뤄야 합니다. 하나를 빠뜨리거나 나중에 경우를 더하면, 컴파일러가 어느 갈래도 다루지 않는 경우를 짚어 줍니다.
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)
없을 수도 있는 값
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)
미리 보이는 에러
실패할 수 있는 함수는 throws로 그렇다고 밝히고, 그 함수를 부르는 곳마다 try가 붙습니다. 코드를 읽기만 해도 에러가 나올 수 있는 곳이 모두 보입니다.
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 토러스 격자에서 콘웨이의 생명 게임을 돌리고 몇 세대를 텍스트로 출력합니다.작은 Lisp 인터프리터토크나이저, 재귀 하강 파서, 환경을 들고 다니는 평가기로 작은 Lisp를 만듭니다. define, if, lambda, 클로저를 지원하고, 런타임 에러는 throws로 알립니다.TCP 에코 서버프로그램 하나가 비어 있는 127.0.0.1 포트에 에코 서버를 띄웁니다. 클라이언트가 줄을 보내고 에코를 다시 읽은 다음 모든 것을 깔끔하게 닫습니다.텍스트 어드벤처방, 출구, 아이템, 잠긴 문이 있는 작은 텍스트 어드벤처입니다. 미리 적어 둔 명령 목록으로 끝까지 플레이합니다.CSV 보고서작은 판매 CSV를 임시 파일에 쓰고 한 줄씩 다시 읽어서 열을 맞춘 지역별 요약 표를 출력합니다.단어 세기텍스트의 줄, 단어, 문자 수를 세고 Dict와 정렬로 가장 자주 나오는 단어 다섯 개를 고릅니다.JSON 파서JSON 값을 enum으로 나타냅니다. 문자 단위 재귀 하강 파서는 에러 위치를 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.