NURL

Cheat sheet

NURL's syntax on one page.

A condensed reference. Each section links to the full page it comes from.

Types

TypeMeaning
vunit
isigned 64-bit integer
uunsigned byte
f64-bit float
bboolean
sC string (i8*)
i8 i16 i32 i64 / u16 u32 u64 / f32sized integers / float
v128 / v256 / v512128-bit (4×i32) / 256-bit (8×i32) / 512-bit (16×i32) SIMD vectors
*Traw pointer
?Toption
!T Eresult
[Tslice
(@ R P*)closure type

Literals and bindings

42          -7           3.14        -2.5e10
`text\n`    T   F                          // string, true, false

: i n 0          // let, explicit type
: ~ i x 0        // mutable
: total ( f )    // inferred
= x 5            // reassign (x must be mutable)

Functions and calls

@ add i a i b → i { ^ + a b }     // declare (prefixes: pub, inline, simd, unsafe, raw)
( add 1 2 )                        // call — always parenthesized
: (@ i i) sq \ i x → i { * x x }  // closure literal
Parameter formMeaning
T ximmutable borrow (default)
inout T xmutable borrow, caller's storage
sink T xtakes ownership

Operators — all prefix, fixed arity

+ - * / %        < > <= >= == !=        << >>
& |  (bool or bitwise)     ^^ (xor)     && || (strict bool)
! expr    (not)      ~ expr  (complement)
^ expr    (return)   \ expr  (try-propagate)
# type expr   (cast)          Z type   (sizeof)

Binary operators take exactly 2 operands — chain with & a & b c for a && b && c.

Control flow

? cond then else                  // ternary
~ cond { body }                   // while
~ item collection { body }        // foreach
break   continue                  // loop exit / next iteration
; { cleanup }                     // defer (LIFO at scope exit)
?? expr { Variant x → ... _ → ... }   // match, exhaustive

Structs and enums

: Point { i x  i y }                  // prefix with `raw :` to seal fields
@ Point { 1 2 }                       // construct
. p x                                 // field access

: | Shape { Circle f  Rect f f }
?? shape { Circle r → ... Rect w h → ... }

Error handling

@ ?T { T v }   @ ?T { F }          // Option: Some / None (`@ ?T { F 0 }` also accepted)
@ !T E { T v }  @ !T E { F e }     // Result: Ok / Err
: x \ ( might_fail )                // try-propagate, returns early on failure
( opt_expect o `msg` )  ( res_expect r `msg` )   // unwrap or panic

Memory

  • A : binding owns a fresh allocation. The compiler frees it automatically at scope exit.
  • inout mutates the caller's value. sink takes ownership.
  • String, Vec, owning structs, containers, closure environments, and all stdlib handles (including TcpConn, UdpSocket, UnixConn, TlsStream, File, Channel, Mutex, Cond, ProcChild, Sqlite) auto-drop when their last owner leaves scope. Only raw nurl_alloc memory inside an unsafe function is freed by hand.
  • Use Arc (read-only) or Locked [T] (mutable) — never Rc — for anything shared across threads.

Common stdlib entry points

$ `stdlib/core/string.nu`
$ `stdlib/std/int.nu` n          // aliased import
( n::int_gcd 12 18 )
NeedModule
Stringscore/string.nu
Growable arraycore/vec.nu
Hash mapstd/hashmap.nu
JSONext/json.nu
HTTP client/serverext/http.nu, ext/http_server.nu
Threads / channelsstd/thread.nu, std/channel.nu
Async fibersstd/async.nu

Next

Last updated on

On this page