The Crow Programming Language

memory

Process memory: a record the standard library holds for the process under a name, shared by its threads — remembered, recalled, revised under the name's lock, forgotten; what a module keeps between calls. Meant for library code — the standard library and packages that need it — which any program or package may import.

Import with use memory — meant for library code: the standard library, and a package that needs it. A record library code holds for the process under a name, shared by its threads — what a module keeps between calls (Magpie's sequencer: the rows put since the last flush, each key's last position and newest row). A program's own state is its variables, and a page's its facts, so a program seldom has a reason to import it; keeping it to library code is a suggestion, not a rule, and any program or package may import it (Vijay, 2026-10-29). A name holds one kind of record, the first it was given: a read, a revision or a write of another kind stops, naming both, in both modes (memory: 'tally' holds Other, not Count — a name holds one kind of record). Names are a tree — forgetting a name forgets the names beneath it (the name and a slash) — and a name that is a path, as canonical writes it, is forgotten when rm removes the path. The compiled program holds each record as its own type, the interpreter its values, under the same names and rules (crow_runtime::memory).

FunctionDescriptionExample
remember[name, record]The record held for the process under the name, replacing what wasProcess memory: use memory
recall[name, default]The record the name holds, or the default where it holds none; typed by the defaultProcess memory: use memory
revise[name, default, f, …]f run under the name's lock, handed the record held (the default where none is) and the rest of the arguments; the record f answers is held and answered. The record is handed over, not copied, so a revision costs what f does; where f's answer can fail it is copied first, and a failure leaves it as it was and is the answer. Two threads revising one name take turns, and f reaching its own name again (a recall, a revision) is refused, where it would wait on itself; it reaches another name only after its own in name order — inside a revision of 'b', 'c' is revised, recalled or remembered and 'a' is refused alike, so that two revisions on two threads never each hold one name and wait on the other's (Vijay: made public again, two names are taken in name order)Process memory: use memory
forget[name]Nothing held under the name nor beneath it: a later read answers its default, and the name may take another kindProcess memory: use memory · The Element Vocabulary
canonical[path]The path made absolute with its links resolved (as given where it cannot be): the name a path's record is kept underProcess memory: use memory

recall reads (the held kind: a derivation may, a view may not); the others change what is held (held.write: a handler, a function or a test). A loop that touches memory runs in order, and nothing leaves the program, so a rehearsal records none.

use memory

struct Count [n]

fn bumped[c, k]
    return Count[c.n + k]

fn bump[k]
    return revise['visits', Count[0], bumped, k].n

log[bump[1]]                          --- 1
log[bump[2]]                          --- 3
log[recall['visits', Count[0]].n]     --- 3

Design Note: process memory holds records, by name. Considered: top-level variables a module's functions write (rejected: a function sees no top-level variable — No Ambient Mutability — and state its threads share needs a lock the language would then need as well); a store of any value (rejected: the compiled program holds a value as its type, and a name holding an int at one call and a list at the next would be checked at every read of every kind — a record is one type per program, so a read of another kind is one comparison, alike in both modes, and the record names what is kept); a lock and an unlock (rejected: a stop between them holds the lock for good) — revise runs a function under the lock instead. Considered for revise: copying the record for the function (rejected: the sequencer's record holds the pending rows, and a copy per put makes every put cost what is pending) — the record is handed over, copied only where the function's answer can fail; and what a module keeps per key is a name per key beneath the module's name (<dir>/#last/<key>), so no revision copies a map of every key. Decided (2026-10-28) for Magpie's sequencer (Magpie's magpie-in-crow.md, 2.4). The flush the sequencer asks for is later's — coalesced, waited for at exit — and run inline by the interpreter, so under crow run -i a put is durable when it answers: a legal schedule, and a slower one. Decided as well (Vijay, 2026-10-28): a form a derivation could call to keep a computed record (kept[name, f, …], for Magpie's footers) was declined: a program keeps nothing in the process behind its own variables, and Magpie's reads keep nothing between calls and are made cheap instead (Magpie's magpie-in-crow.md, 4.2). Process memory had been the standard library's alone, as sys was; keeping both to library code is a suggestion, not a rule (Vijay, 2026-10-29): a package that needs them imports them.

Generated by crow test --docs --write from the language specification, section 11 and 13. Edit the spec, not this page.