21. Keyword Reference
Every Nori keyword, with a one-line meaning and where it is defined. Nori has a small set of reserved words (never usable as identifiers) and a larger set of contextual words (keywords only in a specific position, ordinary identifiers elsewhere; see Lexical Structure.
Reserved words
| Word | Meaning | Chapter |
|---|---|---|
as | import alias: import "…" as name | 13 |
break | exit the innermost (or labeled) loop | 7 |
continue | next iteration of a loop | 7 |
defer | run a statement when the enclosing block ends, by any path | 7 |
else | alternative branch; also the fallback operator | 7, 14 |
enum | declare a sum type | 11 |
false | the Bool false | 3 |
fn | declare a function | 8 |
foreach | iterate a range or collection | 7 |
if | conditional (statement or expression) | 7 |
impl | method / trait implementation block | 10, 12 |
import | bring in a module | 13 |
in | the foreach x in … separator | 7 |
inout | name a value you may change: write-back for a scalar, permission to mutate for a handle; at a store position, share it with the container | 8, 15 |
law | a universally-quantified property | 19 |
let | immutable binding | 4 |
lock | enter a mutex's critical section | 16 |
match | pattern match | 11 |
over | the reduction domain in reduce … over … | 16 |
reduce | parallel reduction | 16 |
region | scoped allocation arena | 15 |
return | return from a function | 8 |
schedule | attach a scheduling strategy to a loop nest | 16 |
set | write-through ownership hint | 15 |
sink | move the value: sink x, sink r.f, sink g on a global (the place is left empty), match sink x, sink parameter | 15 |
spawn | start a concurrent task | 16 |
struct | declare a product type | 10 |
trait | declare an interface | 12 |
true | the Bool true | 3 |
unsafe | raw-memory / FFI block | 17 |
view | a read-only second name that owns nothing and is deep: nothing reachable through it may change; also -> view T results and f: view T fields | 15 |
copy | a deep copy with its own owner; changing it never affects the original | 15 |
var | mutable binding | 4 |
while | conditional loop | 7 |
Contextual words
These are keywords only in the position shown; anywhere else they are ordinary identifiers.
| Word | Meaning | Chapter |
|---|---|---|
pub | export an item from its module | 13 |
for | names the type an impl is for: impl Trait for Type; a name everywhere else, so let for = 1 is legal | 12 |
global | a top-level constant | 4 |
threadlocal | threadlocal global: one copy of the global per thread (per CPU in a freestanding image) | 4, 16 |
frozen | frozen global: written only before the first spawn, so a task may read it | 16 |
naked | naked fn: no prologue or epilogue, for freestanding entry points | 17 |
record | declare a raw memory layout as a type: values are addresses, fields are loads and stores | 17 |
@section / @align / @code32 | on a naked fn: the section its assembly block is placed in, its alignment, and 32-bit mode | 17 |
@irq | on a function: an interrupt handler, which with everything it calls may neither allocate nor block (on an extern fn or a naked fn: its author's word that it does not) | 17 |
@takes(L) / @needs(L) / @sleeps / @nospin | on a function: lock effects: what locks it (or its caller) holds, and whether it may block (@sleeps) or provably never does (@nospin); checked over the whole call graph against a lockorder declaration | 17 |
cstruct | a raw-memory record with C layout: fixed-width fields, cnew/cfree, s.field access, views, sizeof/offsetof | 17 |
packed | packed cstruct: the same, with every field at offset 0,1,2,… (alignment 1, no padding): the x86 tables C alignment cannot say | 17 |
nori | extern nori fn: a Nori-ABI symbol defined in a separately-compiled dependency | 17 |
durable | a global that persists across program runs (durable var) | 4 |
migrate | load an older persisted shape through a converter (durable var X: T migrate from Old with fn; a plain global may carry clauses too, for snapshot() images) | 4 |
transient | a struct field that is derived state: never persisted, rebuilt empty on load, and outside the schema | 4 |
extern | declare a C-ABI function / inline C | 17 |
from | extern fn f(..) -> R from "libz.so.1": the shared library a C function is imported from; also migrate from | 17, 4 |
cfg | conditional compilation | 18 |
namespace | group declarations under a sub-name | 13 |
use | bring a name into scope from a namespace | 13 |
versioned | a value with undo/redo history | 19 |
protocol | a two-party conversation as a type; <role> sends <Type> steps | 16 |
sends | one step of a protocol | 16 |
streams | a protocol step that repeats zero or more times | 16 |
chooses | a protocol step where one role picks a branch | 16 |
await | wait for a Task to finish | 16 |
parallel | fork/join block or parallel loop | 16 |
within | deadline-bounded execution | 16 |
race | run branches, take the first | 16 |
hedge | start a backup only if the primary is slow | 16 |
select | wait on channels and/or a timeout | 16 |
until | async placeholder that upgrades in place | 16 |
yield | publish a best-so-far in a within block | 16 |
never | a whole-program policy that must not be violated | 19 |
shadow / shadows | differential replacement of a function | 19 |
deprecated | warn at every call site of a name you still export | 13 |
with | an oracle for a shadowed function | 19 |
or | the second branch of race/hedge | 16 |
Not keywords
Core operations (printl, push, pop, len, slen, to_str, vec, map, fill, channel, mutex, spawn's partner built-ins, and the rest) are built-in functions, not keywords. They live in the ordinary function namespace and are documented with the types they operate on.
Next: Grammar Summary.