The Neper language in brief
This page condenses the essentials. The normative references are docs/grammar.ebnf (revision 3), docs/llm-neper-card.md (the editing card this page is derived from), docs/spec.md and docs/module-apis.md (the standard library index).
Program shape
use e.io
fn main(a: *mem.Arena, args: []str) -> err {
try io.print("Hello, Neper")
ret ok
}
A program is a run of declarations: use, const, var, error, type, fn and extern. Modules are named by dotted paths (e.io, e.algo.graph) and imported with use.
Bindings and types
letbinds once,varmutates. A binding is typed explicitly (var n: u32 = 0u32) or inferred from its literal.- Literals carry their type:
1u64,1.5f64,u8(200),true,nil,zero. - Casts are explicit and checked:
i64(x),u32(n),f64(i); a narrowing cast traps out of range in debug builds. - Strings are byte slices (
str) with escapes limited to\n \t \r \\ \" \' \0 \xHH; use the modules for Unicode work.
Errors, try and defer
errordeclares an error set; functions answererrand returnret okorret Name.try f()propagates an error,try f()as a statement orlet (v, e) = f()when the answer is a tuple.deferruns at scope exit; resources such as files and windows areresourcetypes closed by the runtime or an explicit close.
Structs, enums and unions
structfields are named and typed; literals areType { field: value }.enumis an integer with named members;switchis exhaustive over them.unionis the C-layout escape hatch forexternABIs; the safe tagged form isenumwith payload arms.
Comptime and generics
fn largest[T: type](xs: []const T) -> T { ... }
Type parameters are written [T: type]; functions and types with compile-time arguments are monomorphised. Modules expose generic helpers (e.g. channel.send[i64]), and comptime parameters carry array lengths and flags.
No-shadowing, and reserved words
A local may not reuse a module-scope function, type or module name (the E-NAME-0003 diagnostic). The full keyword list is in the editing card: as break case const continue default defer else enum error extern false fn for if in isize let nil nocheck ok own resource ret shared struct switch true try type undef union unreachable use usize var when while zero.
Standard library
Everything is in modules under e.: e.io, e.mem, e.str, e.net.http, e.game, e.ui, e.chart, e.algo.*, e.math.* and more. The complete index is docs/module-apis.md; the machine-readable summary is llms.txt.
Next
Install Neper, then read the get-started walkthrough and the measured blog posts.