pub enum Prim {
Show 110 variants
Add,
Sub,
Mul,
Div,
Rem,
Neg,
Abs,
Sqrt,
Sin,
Cos,
Trunc,
ToFloat,
Eq,
Ne,
Lt,
Le,
Gt,
Ge,
And,
Or,
Not,
ToStr,
StrTrim,
StrToInt,
StrLen,
StrSlice,
StrSplit,
StrJoin,
StrContains,
StrStartsWith,
StrEndsWith,
StrUpper,
StrLower,
StrReplace,
StrIndexOf,
StrRepeat,
StrChars,
StrIsEmpty,
ListLen,
ListIsEmpty,
ListMin,
ListMax,
ListSum,
ListUnique,
ListGet,
ListSlice,
ListReverse,
ListTake,
ListDrop,
ListContains,
ListIndexOf,
ListFold,
ListAll,
ListAny,
ListFlatMap,
ListZip,
ListAppend,
MapKeys,
MapMerge,
JsonParse,
JsonRender,
TimeFormat,
TimeParse,
Digest,
DigestKeyed,
DigestEq,
HexEncode,
HexDecode,
Base64Encode,
Base64Decode,
UuidParse,
UuidVersion,
HttpFetch,
MapList,
FilterList,
ConcatLists,
SortBy,
MapGet,
MapInsert,
MapRemove,
MapValues,
MapContains,
MapLen,
OptionIsSome,
OptionUnwrapOr,
HtmlEl,
HtmlText,
HtmlAttr,
HtmlOn,
HtmlKey,
NewUuid,
Now,
SecretEnv,
Raise,
Try,
Parallel,
InternalOf,
Reveal,
MergeClients,
Presence,
Awareness,
Freshness,
Gestures,
StreamFilterMap,
Fold,
Durable,
SignalMap,
SignalMap2,
PerSession,
Decide,
}Expand description
A primitive operation. Everything the standard library provides in Phase 1.
Variants§
Add
Sub
Mul
Div
Rem
Neg
Abs
abs, sqrt and Int → Float, which are the three the numeric tower needs before any
of SICP §1.1.7 will run (docs/27 §27.2). Abs is resolved from its operand the way the
arithmetic operators are; the other two are monomorphic.
Sqrt
Sin
Cos
Trunc
ToFloat
Eq
Ne
Lt
Le
Gt
Ge
And
Or
Not
ToStr
StrTrim
StrToInt
StrLen
StrSlice
StrSplit
StrJoin
StrContains
StrStartsWith
StrEndsWith
StrUpper
StrLower
StrReplace
StrIndexOf
StrRepeat
StrChars
StrIsEmpty
ListLen
ListIsEmpty
ListMin
ListMax
ListSum
ListUnique
ListGet
ListSlice
ListReverse
ListTake
ListDrop
ListContains
ListIndexOf
ListFold
ListAll
ListAny
ListFlatMap
ListZip
ListAppend
MapKeys
MapMerge
JsonParse
JsonRender
TimeFormat
TimeParse
Digest
DigestKeyed
A message authentication code: the one primitive whose input is a secret[Str] and whose
output is a Str. Charged cap.sign rather than left free, so a view cannot mint one —
docs/adr/0014 is the record of the decision and §3.5 is what it is measured against.
DigestEq
Constant-time equality, for the caller comparing a digest against one that arrived.
HexEncode
HexDecode
Base64Encode
Base64Decode
UuidParse
Validates and normalises: two spellings of one identifier must not be two map keys.
UuidVersion
HttpFetch
MapList
FilterList
ConcatLists
SortBy
MapGet
MapInsert
MapRemove
MapValues
MapContains
MapLen
OptionIsSome
OptionUnwrapOr
HtmlEl
HtmlText
HtmlAttr
HtmlOn
HtmlKey
NewUuid
Mints a fresh id. Nondeterministic, so §3.7 forbids it inside a fold; the client mints entity ids instead, which is “the small tell that browsers here are replicas, not terminals”.
Now
Reads the wall clock. The other half of §3.7’s rule: “time is data on the envelope”.
SecretEnv
Reads a secret from the process environment, yielding a secret[Str] (§3.5).
Raise
raise e — fail with a value.
The atom it performs is raises(T), which depends on the type of its argument, so the
checker attaches it where that type is known rather than Prim::effects declaring it.
This is the first primitive whose row is not a constant, and it is why that table’s doc
says “the atoms this primitive performs itself”.
Try
try: block — run a thunk, and turn a raise of the named type into an Err.
Two arguments: the thunk, and the name of the error type this handler catches. The name is
what stops a handler from catching a failure it cannot type — a caller’s function may raise
something this try never heard of, and that has to keep travelling.
Parallel
parallel: block — run the scope’s children, then its tail with their results bound.
The arguments are the children’s thunks followed by the continuation, so a child cannot
outlive the scope: there is no handle, and the only thing that can read a child’s result is
the one lambda the scope built. That is docs/38
§38.4’s “spawn/await as effect operations, the scope as their handler” with the handler as
the only form — the operations are not separately reachable.
The children are independent by construction (none of them can name another) and no child may perform an effect another child could observe, so the scope’s answer does not depend on the order they ran in. A backend may therefore run them together; running them in the order they are written is a correct implementation of that, and is what the tree-walker does.
InternalOf
Wraps a value as internal[T]: storable, never Sendable.
Reveal
Unwraps one. Performs cap.internal, so only the authority chokepoint can do it.
MergeClients
Presence
presence() — who is connected now, as a signal that is not a function of the log.
D6’s last row. It performs cap.presence rather than an atom of its own, which is F16
(docs/14) taken literally: “presence signals
leak who-is-online; gate behind a capability like any other view”. The capability is also
what places it — no tier below the server discharges a cap.* — so a fold cannot read the
roster and a view reaches it across a declared edge.
Awareness
awareness(f) — what every subscriber contributes, keyed by actor.
Presence with a payload, and the same three rules for the same reasons: a non-log input to
a view, bounded because the key is a name the client chooses (docs/82 §82.5), and refused
at the chokepoint because an event whose existence depended on where somebody’s cursor was
would not survive a replay. It carries cap.presence rather than a capability of its own —
a roster with payloads discloses strictly more than a roster, and gating the smaller
disclosure while leaving the larger one open would be the wrong way round.
f is a function of the Session, which is what the server already holds for every
connection. docs/104 §104.8 has the half that needs more than that and why it waits.
Freshness
freshness() — whether the page being rendered is the confirmed state or a guess.
§3.7’s “Signal[T] carries a freshness dimension (confirmed | pending(n)) that UI code
can render ("saving…") — staleness is typed, not pretended away”. It is the mirror image
of Prim::Presence: presence is a fact the server holds about its sockets and cannot
reach a Mode B client, and freshness is a fact the client holds about its own guesses and
is Confirmed everywhere else. No capability, because nothing is disclosed by it — a client
counting its own unacknowledged commands is reading itself.
Gestures
gestures(step, init) — the non-durable fold
docs/10 D30 decides the shape of.
The mirror of Prim::MergeClients on the other side of the wire: that one is every
client’s proposals arriving at the one place time enters, and this is one client’s gestures
arriving nowhere else at all. Nothing here is proposed, validated or recorded — a
gesture is a movement of the interface, which is why it is neither a Command nor an
Event, the two words that already mean something about the log.
It carries dom, and that is the whole of its placement: no tier but the client discharges
it (crate::ty::Tier::discharges), so this is client-placed by machinery that was already
there, and durable is on a tier the client cannot reach. D3’s invariant is untouched
rather than weakened — replay reproduces everything that was ever in the log, and no gesture
ever was.
StreamFilterMap
Fold
Durable
SignalMap
SignalMap2
PerSession
§3.8’s per-session view: todos.map(filter_by(session.user)). First-class because “the
fanout cost becomes a first-class engineering concern”.
Decide
The authority chokepoint: the sole consumer of ingress, holding the accumulator so that first-writer-wins and ownership can be decided (§3.7, F2).
Implementations§
Source§impl Prim
impl Prim
pub fn name(self) -> &'static str
Sourcepub fn effects(self) -> Vec<Effect>
pub fn effects(self) -> Vec<Effect>
The atoms this primitive performs itself.
The polymorphic half of a primitive’s row — map_list’s e, which is whatever its function
argument does — lives in the scheme in crate::prelude, because a row variable is not a
constant. A test holds the two in agreement.