Directive reference

Every directive in the closed directive registry (spec/core/code.md §4.1) — the bracketed [?…] forms that drive pattern dispatch, comprehensions, binding, iterators, resilience, services, concurrency, and async. Each entry is generated from the co-located reference source and, where the conformance corpus backs it, carries a runnable example pinned verbatim to a green fixture.

?match

[?match VALUE [case PAT BODY]… [else …]] -> result — Structural pattern dispatch: test a value against ordered [case] arms (literal, wildcard `_`, type guard, binding pattern, [when] guard) and evaluate the first match; single-arm and multi-arm forms.

Core — pattern dispatch (single-arm + multi-arm) · §5.2, §8.2

            [?match 200 [case 200 :match] [else :miss]]
          
            :match
          

?modify

[?modify TREE PATH ACTION…] -> tree — Pure-functional update: walk a CXPath selection in a tree and apply actions ([set]/[delete]/[rename]/[set-attr]/[append]/[insert-before]…), returning a new tree; a path that matches nothing returns the tree unchanged.

Core — pure-functional update · §8.10

            [?modify $doc //missing [delete]]
          
            [users [user [name 'Alice']]]
          

?with-open

[?with-open RESOURCE $name BODY] -> result — Scoped-resource RAII: bind a closeable resource, evaluate BODY, and close the resource deterministically when the block exits (success or error).

Core — scoped-resource RAII · §8.10.7

            [?with-open [?async [+ 21 21]] $f [?await $f]]
          
            42
          

?with-scope

[?with-scope {BINDINGS} EXPR…] -> last — Dynamic-scoped context: install a map of dynamic bindings for the duration of the block; the value is the last expression.

Core — dynamic-scoped context · §8.10.8

            [?with-scope {a: 1} 100 200]
          
            200
          

?str

[?str "TEMPLATE"] -> string — Compile-time string interpolation: expand `{expr}` holes in a template; `{{` / `}}` are literal braces.

Core — compile-time string interpolation · §8.12

            [?str "100{{pct}}"]
          
            '100{pct}'
          

?element

[?element NAME-EXPR CHILD…] -> element | () — Computed-name element construction: build an element whose name is computed at runtime; an empty `()` name yields absence.

Core — computed-name element construction · §6.4.2

            [?element () "x"]
          
            ()
          

?attr

[?attr NAME-EXPR VALUE-EXPR] (attr position) -> attribute | omitted — Computed-name attribute, valid only in attribute position; an empty `()` name omits the attribute.

Core — computed-name attribute (attr position only) · §6.4.2

            [?element "box" [?attr () "red"]]
          
            [box]
          

?entry

{[?entry KEY-EXPR VALUE-EXPR]} -> map entry — Computed-key map entry, valid only inside a `{…}` map literal.

Core — computed-key map entry (inside `{…}` only) · §6.4.2

            {[?entry "k" 1]}
          
            {k: 1}
          

?name

[rename [?name NAME-EXPR]] / [set-attr [?name …] …] — Shared computed-name sub-form used inside [rename] and [set-attr] actions to supply a runtime-computed name.

Core — shared name sub-form (`set-attr`/`rename`) · §6.4.2

            [?modify $doc //user [rename [?name "person"]]]
          
            [users [person name=old]]
          

?quote

[?quote FORM] -> inert tree — Quasiquote: produce FORM as inert data (eager, two-color hygiene); bare `$x` becomes `[cx:var 'x']` rather than dereferencing.

Core — quasiquote (eager; two-color hygiene) · §6.4.3

            [?quote [a $x]]
          
            [a [cx:var 'x']]
          

?unquote

[?quote […[?unquote EXPR]…]] -> spliced value — Quasiquote hole: evaluate EXPR and graft its single value into the surrounding quoted tree; `()` removes the hole.

Core — quasiquote hole (single value) · §6.4.3

            [?quote [box [?unquote ()]]]
          
            [box]
          

?splice

[?quote […[?splice EXPR]…]] -> grafted sequence — Quasiquote hole: evaluate EXPR and graft its sequence elements in place; `()` grafts nothing.

Core — quasiquote hole (sequence graft) · §6.4.3

            [?quote [box [?splice ()]]]
          
            [box]
          

?eval

[?eval TREE [context {…}] [opts {…}]] -> value — Tree-eval: evaluate a CX tree as a program in the `cx:eval` sandbox; requires the `eval` capability.

Core — tree-eval (reuses `cx:eval` sandbox) · §6.4.4

            [?eval 42]
          
            42
          

?for

[?for [in $x SRC] [where …]? CLAUSE… [yield EXPR]] -> sequence — For-comprehension over a Sequence outer (D15): generators, [where] filters, [order-by]/[group-by]/[limit], and [yield]; produces a flat Sequence. [where] takes a PREFIX predicate — `[where [= $x/@attr value]]` — which is the reliable form everywhere (also inside `not(…)` and as a node-set predicate `//u[@attr=value]`); a bare infix comparison `[where $x/@attr=value]` is a parse error that points back at the prefix form.

Core — for-comprehension (Sequence outer; D15) · §7

            [?for [in $x [$range 1 5]] [yield $x]]
          
            1
2
3
4
5
          

?for-array

[?for-array [in $x SRC]… [yield-array EXPR]] -> array — For-comprehension with an Array outer (D15): like [?for] but materialises an Array via [yield-array].

Core — for-comprehension (Array outer; D15) · §7

            [?for-array [in $x [$range 1 3]] [in $y [$range 1 2]] [yield-array [$x, $y]]]
          
            [[1, 1], [1, 2], [2, 1], [2, 2], [3, 1], [3, 2]]
          

?for-map

[?for-map [in $x SRC]… [yield-map K V]] -> map — For-comprehension with a Map outer (D15): emit key/value pairs via [yield-map] into a Map.

Core — for-comprehension (Map outer; D15) · §7

            [?for-map [in $x [$range 1 3]] [yield-map $x [* $x $x]]]
          
            {1: 1, 2: 4, 3: 9}
          

?let

[?let [= $x EXPR]… BODY] -> result — Local binding: bind one or more names in a lexical scope and evaluate the body; bindings may nest.

Core — local binding · §8

            [?let [= $a 10] [= $b 32] [+ $a $b]]
          
            42
          

?fn

[?fn ($a $b…) BODY] / [?fn $x BODY] -> function — Function literal (closure): a first-class anonymous function; single-parameter form omits the parens.

Core — function literal · §8

            [?let [= $double [?fn ($x) [* $x 2]]] [$double 21]]
          
            42
          

?def

[?def NAME [scope=…] [pure|impure]? (PARAMS) BODY] — Module-level function definition; `scope=public` exports it, purity is declared, and the name is called as `[$NAME …]`.

Module — module-level function · §12.2

            [?def add ($a $b) [+ $a $b]]
[$add 2 3]
          
            5
          

?lib

[?lib 'cx-stdlib/MODULE' [as=ALIAS]?] — Module import: bind a module (bundled or local) so its public functions are callable as `[$module:fn …]`.

Module — module import · §12.1

            [?lib 'cx-stdlib/math']
[$math:abs -3]
          
            3
          

?const

[?const NAME EXPR] — Module-level constant; resolution is load-order-independent (constants may forward-reference each other).

Module — module-level constant · §12.3

            [?const B [* A 10]]
[?const A 5]
B
          
            50
          

?do

[?do E …] -> null — Evaluate-for-effect sequencing: one or more expressions evaluate in order with values discarded; the first [err …] result propagates immediately, and success yields null (a present unit, never absence).

Core — evaluate-for-effect sequencing · §8.14

            [?do 1 2 3]
          
            null
          

?loop

[?loop [= $x INIT]… BODY] with [break V?] / [continue V…?] -> value of [break] — Condition-driven loop as anonymous trampolined tail recursion: [continue …] rebinds the declared bindings positionally for the next pass, [break …] exits with the loop's value, and any other tail value raises CXER0100 (all-explicit exits).

Core — condition-driven loop (explicit exits) · §8.15

            [?loop [= $i 1] [= $acc 0]
  [?if [> $i 5] [then [break $acc]]
    [else [continue [+ $i 1] [+ $acc $i]]]]]
          
            15
          

?if

[?if COND [then …] [else …]] -> branch — Conditional: evaluate COND for its effective boolean value and take the [then] or [else] branch.

Core — conditional · §8

            [?if [= :ok :ok] [then :match] [else :no-match]]
          
            :match
          

?else

[?else EXPR DEFAULT] -> value-or-default — Value-or-default coalesce (getOrElse): yield EXPR unless it is an error or absence `()`, in which case yield DEFAULT.

Core — value-or-default coalesce (`getOrElse`; on err + absence) · §8.13

            [?else () 'd']
          
            'd'
          

?pipe

[?pipe VALUE STAGE…] -> result — Pipeline (prefix-only): thread a value through bare stages left to right; absence short-circuits, `[tap]` observes without altering flow.

Core — pipeline (prefix-only; bare stages; `[tap]`) · §6.4, §8.9

            [?pipe () [$count]]
          
            0
          

?map

[?map SRC [using FN] [par]? [ordered]?] -> sequence — Map: apply a function over a source, lazily by default; `[par]` runs in parallel and `[ordered]` preserves source order.

Core — map (sequential or `[par]`) · §8

            [?map (1, 2, 3, 4) [using [?fn $x [* $x 10]]]]
          
            (10, 20, 30, 40)
          

?reduce

[?reduce SRC [using FN] [init V]] -> value — Reduce / left fold: combine the elements of a source with an accumulator function and an initial value.

Core — reduce / fold (sequential or `[par]`) · §8

            [?reduce (1, 2, 3, 4) [using [?fn ($a $b) [- $a $b]]] [init 10]]
          
            0
          

?filter

[?filter SRC [using PRED]] -> iterator — Iterator combinator: keep only the elements for which the predicate holds.

Iterator stdlib — filter by predicate · §8

            [?filter (1, 2, 3, 4, 5, 6) [using [?fn $x [$odd $x]]]]
          
            (1, 3, 5)
          

?take

[?take N SRC] -> iterator — Iterator combinator: the first N elements of a source.

Iterator stdlib — prefix of `count` items · §8

            [?take 3 [?map (1, 2, 3, 4, 5) [using [?fn $x [* $x 2]]]]]
          
            (2, 4, 6)
          

?drop

[?drop N SRC] -> iterator — Iterator combinator: the source with its first N elements skipped.

Iterator stdlib — suffix after `count` items · §8

            [?drop 2 (10, 20, 30, 40, 50)]
          
            (30, 40, 50)
          

?zip

[?zip SRC-A SRC-B…] -> iterator of tuples — Iterator combinator: per-position tuples across two or more sources, stopping at the shortest.

Iterator stdlib — per-position tuples · §8

            [?zip (1, 2, 3) ("a", "b", "c")]
          
            ((1, 'a'), (2, 'b'), (3, 'c'))
          

?enumerate

[?enumerate SRC] -> iterator of (i, item) — Iterator combinator: pair each element with its zero-based index.

Iterator stdlib — emit `(i, item)` pairs · §8

            [?enumerate ("a", "b", "c")]
          
            ((0, 'a'), (1, 'b'), (2, 'c'))
          

?chunks

[?chunks N SRC] -> iterator of groups — Iterator combinator: group consecutive elements into runs of N (the final group may be short).

Iterator stdlib — group by `count` · §8

            [?chunks 2 (1, 2, 3, 4, 5)]
          
            ((1, 2), (3, 4), (5))
          

?concat

[?concat SRC…] -> iterator — Iterator combinator: flatten one level across the given sources, concatenating them in order.

Iterator stdlib — flatten one level across sources · §8

            [?concat (1, 2) (3, 4)]
          
            (1, 2, 3, 4)
          

?chain

[?chain SRC…] -> iterator — Iterator combinator: alias of [?concat] — concatenate sources end to end.

Iterator stdlib — alias of `[?concat]` · §8

            [?chain (1, 2) (3, 4) (5, 6)]
          
            (1, 2, 3, 4, 5, 6)
          

?cycle

[?cycle SRC max=N] -> iterator — Iterator combinator: repeat a source cyclically, bounded by `max`.

Iterator stdlib — bounded repeat · §8

            [?cycle (1, 2, 3) max=7]
          
            (1, 2, 3, 1, 2, 3, 1)
          

?scan

[?scan SRC [using FN] [init V]] -> iterator — Iterator combinator: emit the running-fold prefixes (every intermediate accumulator), starting from the initial value.

Iterator stdlib — running-fold prefixes · §8

            [?scan (1, 2, 3, 4) [using [?fn ($a $b) [+ $a $b]]] [init 0]]
          
            (0, 1, 3, 6, 10)
          

?flatten

[?flatten SRC] -> iterator — Iterator combinator: flatten one level of nesting in a source of sequences.

Iterator stdlib — flatten one level of nesting · §8

            [?flatten ((1, 2), (3, 4), (5))]
          
            (1, 2, 3, 4, 5)
          

?partition

[?partition SRC [using PRED]] -> (matches, non-matches) — Iterator combinator: split a source into the elements that satisfy the predicate and those that do not.

Iterator stdlib — split by predicate · §8

            [?partition (1, 2, 3, 4, 5, 6) [using [?fn $x [$odd $x]]]]
          
            ((1, 3, 5), (2, 4, 6))
          

?group-by

[?group-by SRC [using KEY-FN]] -> grouped pairs — Iterator combinator: group elements by a computed key, preserving first-seen key order.

Iterator stdlib — group by key · §8

            [?group-by (1, 2, 3, 4, 5, 6) [using [?fn $x [$mod $x 2]]]]
          
            (('1', (1, 3, 5)), ('0', (2, 4, 6)))
          

?to-sequence

[?to-sequence ITER] -> sequence — Force-materialise an iterator into a Sequence.

Force-materialise — Iterator → Sequence · §8

            [?to-sequence [?map (1, 2, 3, 4) [using [?fn $x [* $x $x]]]]]
          
            (1, 4, 9, 16)
          

?to-array

[?to-array ITER] -> array — Force-materialise an iterator into an Array.

Force-materialise — Iterator → Array · §8

            [?to-array [?map (1, 2, 3) [using [?fn $i [* $i $i]]]]]
          
            [1, 4, 9]
          

?to-map

[?to-map ITER-OF-PAIRS] -> map — Force-materialise an iterator of (key, value) pairs into a Map.

Force-materialise — Iterator-of-pairs → Map · §8

            [?to-map (("a", 1), ("b", 2), ("c", 3))]
          
            {a: 1, b: 2, c: 3}
          

?view

[?view EXPR] -> view — View opt-in: request a zero-copy slice view over a single expression (e.g. `$xs[a:b]`).

View opt-in — zero-copy slice intent on one expr · §8

            [?let [= $xs (10, 20, 30, 40, 50)] [?view $xs[2:4]]]
          
            (20, 30, 40)
          

?views

[?views EXPR…] -> result — View opt-in: flip on view semantics for a scoped block of expressions.

View opt-in — scoped view flip over a block · §8

            [?let [= $xs (10, 20, 30, 40, 50)] [?views $xs[1:2]]]
          
            (10, 20)
          

?retry

[?retry max=N [delay=…] [backoff=…] BODY] -> result — Resilience: re-run BODY up to `max` attempts on failure, with optional delay/backoff/jitter.

Resilience · §10.2

            [?retry max=3 42]
          
            42
          

?timeout

[?timeout DURATION BODY] -> result — Resilience: bound BODY by a duration; on elapse yields a timeout error (CXER0141). Enforced against LOGICAL time — `[?sleep DUR mock]` advances the clock and trips it; a real wall-clock-blocking body is NOT interrupted (real-time cancellation requires the production scheduler).

Resilience · §10.2

            [?timeout 1s fast]
          
            fast
          

?circuit-breaker

[?circuit-breaker threshold=… window=… reset=… min-samples=… BODY] — Resilience: trip open when the failure rate over a window exceeds the threshold, short-circuiting until the reset interval elapses.

Resilience · §10.2

            [?circuit-breaker threshold=0.5 window=60s reset=30s min-samples=10 7]
          
            7
          

?fallback

[?fallback PRIMARY [recover-with ALT]] -> result — Resilience: evaluate PRIMARY and, on failure, recover with the [recover-with] branch (which can bind `$err`).

Resilience · §10.2

            [?fallback [body primary] [recover-with secondary]]
          
            primary
          

?rate-limit

[?rate-limit max=N per=DURATION [name=…] BODY] -> result — Resilience: admit at most `max` evaluations per window; over-limit calls yield a rate-limit error.

Resilience · §10.2

            [?for [in $i (1, 2, 3)]
      [yield [?rate-limit max=5 per=1s name="rl-001" $i]]]
          
            1
2
3
          

?bulkhead

[?bulkhead max-concurrent=N queue=Q BODY] -> result — Resilience (EXPERIMENTAL): cap concurrent executions at `max-concurrent`; saturation yields CXER0152. Immediate-reject works, but the bounded `queue`/backpressure engages ONLY under the cooperative scheduler (`[?test-concurrent]`) and the slot cap is not reliably enforced under real thread contention. Not the `[par]` bounding mechanism (#94 — `[par N]` owns width); for production load-shedding prefer `[?rate-limit]` or a buffered `[?channel]`.

Resilience · §10.2

            [?bulkhead max-concurrent=4 queue=0 ran]
          
            ran
          

?http-service

[?http-service on=… port=… name=… [resource …]…] -> service-handle — Services: stand up an HTTP service from declarative [resource] routes; evaluates to a service handle.

Services · §10.3

            [?let [= $svc [?http-service on=http port=0 name="svc-020" grace-period=5s
                [resource [get "/quick"]
                   [response status=200 body="done"]]]] [= $_ [?stop $svc]] [?wait-for service=$svc]]
          
            [terminated name=svc-020 reason=graceful]
          

?service-handle

[?service-handle name=NAME] -> handle — Services: look up a running service by name to obtain its handle.

Services · §10.3

            [?let [= $_ [?http-service on=http port=0 name="svc-021"
              [resource [get "/"] [response status=200 body="ok"]]]] [= $h [?service-handle name="svc-021"]] [= $_ [?stop $h]] [terminated name="svc-021" reason="graceful"]]
          
            [terminated name=svc-021 reason=graceful]
          

?http-client

[?http-client target=URL] -> client — Clients: construct an HTTP client bound to a target; pipe request verbs through it.

Clients · §10.3

            [?let [= $c [?http-client target="http://localhost:1"]] [?pipe $c [$get _ "/"]]]
          
            [err code=cx-err:CXER0180 message='connection refused']
          

?worker

[?worker name=NAME [body …]] -> worker-handle — Concurrency: spawn a named worker evaluating a body; evaluates to a worker handle.

Concurrency · §10.4

            [?let [= $w [?worker name="w1" [body 42]]] [?wait-for worker=$w]]
          
            42
          

?worker-handle

[?worker-handle name=NAME] -> handle — Concurrency: look up a running worker by name to obtain its handle.

Concurrency · §10.4

            [?let [= $_ [?worker name="w4" [body lookupable]]] [= $h [?worker-handle name="w4"]] [?wait-for worker=$h]]
          
            lookupable
          

?channel

[?channel name=NAME buffer=N] -> channel — Concurrency: create a named channel with a bounded buffer.

Concurrency · §10.4

            [?let [= $ch [?channel name="c1" buffer=1]] [= $_ [?send "hello" to=$ch]] [?receive from=$ch]]
          
            'hello'
          

?send

[?send VALUE to=CHANNEL] -> () — Concurrency: send a value into a channel, blocking when the buffer is full.

Concurrency · §10.4

            [?let [= $ch [?channel name="c1" buffer=1]] [= $_ [?send "hello" to=$ch]] [?receive from=$ch]]
          
            'hello'
          

?receive

[?receive from=CHANNEL] -> value — Concurrency: receive the next value from a channel, blocking when empty.

Concurrency · §10.4

            [?let [= $ch [?channel name="c1" buffer=1]] [= $_ [?send "hello" to=$ch]] [?receive from=$ch]]
          
            'hello'
          

?try-send

[?try-send VALUE to=CHANNEL timeout=…] -> () | err — Concurrency: send with a timeout; yields a send-timeout error instead of blocking indefinitely.

Concurrency · §10.4

            [?let [= $ch [?channel name="c5" buffer=1]] [= $_ [?send "first" to=$ch]] [?try-send "second" to=$ch timeout=50ms]]
          
            [err code=cx-err:CXER0201 message='send timed out']
          

?try-receive

[?try-receive from=CHANNEL timeout=…] -> value | err — Concurrency: receive with a timeout; yields a receive-timeout error instead of blocking indefinitely.

Concurrency · §10.4

            [?let [= $ch [?channel name="c6" buffer=1]] [?try-receive from=$ch timeout=50ms]]
          
            [err code=cx-err:CXER0202 message='receive timed out']
          

?close

[?close CHANNEL] -> () — Concurrency: close a channel; drained receives on a closed channel yield a channel-closed error.

Concurrency · §10.4

            [?let [= $ch [?channel name="c4" buffer=2]] [= $_ [?send "a" to=$ch]] [= $_ [?close $ch]] [= $first [?receive from=$ch]] [= $second [?receive from=$ch]] ([r1 $first], [r2 $second])]
          
            ([r1 'a'], [r2 [err code=cx-err:CXER0200 message='channel closed']])
          

?select

[?select [case [from CH $m] …]… [case [timeout D] …]?] -> arm — Concurrency: wait on multiple channel operations and run the arm of the first that is ready; an optional [timeout] arm bounds the wait.

Concurrency · §10.4

            [?let [= $a [?channel name="sa" buffer=1]] [= $b [?channel name="sb" buffer=1]] [= $_ [?send "from-a" to=$a]] [?select
[case [from $a $msg] [picked ch="a" value=$msg]]
[case [from $b $msg] [picked ch="b" value=$msg]]]]
          
            [picked ch=a value=from-a]
          

?stop

[?stop HANDLE] -> () — Lifecycle: request graceful shutdown of a service or worker.

Lifecycle · §10.3, §10.4

            [?let [= $svc [?http-service on=http port=0 name="svc-020" grace-period=5s
                [resource [get "/quick"]
                   [response status=200 body="done"]]]] [= $_ [?stop $svc]] [?wait-for service=$svc]]
          
            [terminated name=svc-020 reason=graceful]
          

?wait-for

[?wait-for worker=H | service=H] -> result — Lifecycle: block until a worker or service completes/terminates and yield its result.

Lifecycle · §10.3, §10.4

            [?let [= $w [?worker name="w1" [body 42]]] [?wait-for worker=$w]]
          
            42
          

?async

[?async EXPR] -> future — Async: evaluate EXPR concurrently, returning a future.

Async · §10.5

            [?let [= $f [?async 42]] [?await $f]]
          
            42
          

?await

[?await FUTURE] -> value — Async: block until a future is done and yield its value (or its error).

Async · §10.5

            [?let [= $f [?async 42]] [?await $f]]
          
            42
          

?await-all

[?await-all (F…)] -> sequence — Async: await every future and yield their values as a sequence; any non-done future surfaces an error.

Async · §10.5

            [?let [= $a [?async 1]] [= $b [?async 2]] [= $c [?async 3]] [?await-all ($a, $b, $c)]]
          
            (1, 2, 3)
          

?await-any

[?await-any (F…)] -> value — Async: yield the first future to succeed, skipping failed ones.

Async · §10.5

            [?let [= $bad [?async [err code='bad' message='bad']]] [= $good [?async good]] [?await-any ($bad, $good)]]
          
            good
          

?await-race

[?await-race (F…)] -> value — Async: yield the first future to settle and cancel the losers.

Async · §10.5

            [?let [= $fast [?async fast]] [= $slow [?async [?let [= $_ [?sleep 10s mock]] slow]]] [= $winner [?await-race ($fast, $slow)]] [= $slow-state [?await $slow]] [pair [winner $winner] [slow-state $slow-state]]]
          
            [pair [winner 'fast'] [slow-state [err code=cx-err:CXER0260 message='operation cancelled']]]
          

?cancel

[?cancel FUTURE] -> () — Async: request cancellation of a future; a cancelled await yields a cancellation error.

Async · §10.5

            [?let [= $f [?async [?sleep 10s mock]]] [= $_ [?cancel $f]] [?await $f]]
          
            [err code=cx-err:CXER0260 message='operation cancelled']
          

?check-cancel

[?check-cancel] -> () — Async: cooperative cancellation point — surfaces a cancellation error if the surrounding future was cancelled.

Async · §10.5

            [?let [= $f [?async [?let [= $_ [?sleep 10s mock]] [?check-cancel]]]]
  [= $_ [?cancel $f]]
  [?match [?await $f]
    [case [err @code='cx-err:CXER0260'] [cancelled]]
    [else [other]]]]
          
            [cancelled]
          

?sleep

[?sleep DURATION [mock]?] -> [ok] — Async: pause for a duration; the `mock` flag uses the deterministic mock clock.

Async · §10.5

            [?sleep 1ms mock]
          
            [ok]
          

?with-error-hook

[?with-error-hook [observe [using FN]] BODY] -> result — Core: install an observe/enrich/report hook over errors raised in BODY; passes the value through unchanged when there is no error.

Core — error observe / enrich / report hook · §9.6

            [?with-error-hook [observe [using [?fn ($e) $e]]] 42]
          
            42
          

?with-caps

[?with-caps [deny CAP]… BODY] -> result — Core: narrow capabilities for the dynamic extent of BODY (deny-only); BODY runs with the reduced authority.

Core — capability narrowing (deny-only) · `security.md` §3

            [?def build-and-run scope=public impure [returns any]
      ($tag::string $attr-name::string $factor::int $payload::int)
  [?let
    [= $code [?quote [* [?unquote $payload] [?unquote $factor]]]]
    [= $result [?with-caps [deny net] [deny subprocess]
                  [?eval $code [context {}] [opts {max-depth: 4}]]]]
    [?element $tag [?attr $attr-name "scaled"] [result $result]]]]
[$build-and-run "report" "kind" 3 14]
          
            [report kind=scaled [result 42]]
          

?secret

[?secret VALUE] -> secret — Core: mark a value as secret so it renders redacted (`‹redacted›`) at boundaries.

Core — mark a value secret (redacted at boundaries) · `cxdm.md` §12

            [?secret sk-abc]
          
            '‹redacted›'
          

?reveal

[?reveal SECRET] -> cleartext — Core: declassify a secret to its cleartext; gated by the `secret-reveal` capability.

Core — declassify a secret (gated by `secret-reveal`) · `cxdm.md` §12

            [?reveal [?secret sk-abc]]
          
            sk-abc
          

?meta

[?meta {KEY: VALUE…} FORM] -> FORM — Core: attach an inert metadata map to the value of FORM; the value is unchanged and only `meta-of` and the XML serializer observe the map.

Core — inert metadata annotation on a value · §4.2

            [?let [= $doc [?meta {author: alice} [report "Q3"]]] [meta-of $doc]]
          
            {author: alice}