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
*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
( 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
?? expr { Variant x  ... _  ... }   // match, exhaustive

Structs and enums

: Point { i x  i y }
@ 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 0 }        // Option: Some / None
@ !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.
  • You must manage Vec, String, and an escaping closure environment by hand. Free them yourself.
  • Use Arc (not Rc) for anything shared across threads.

Common stdlib entry points

$ `stdlib/core/string.nu`
$ `stdlib/std/vec.nu` v          // aliased import
( v::vec_new [i] )
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