CX · Reference guidecx
PlaygroundDownloadsAboutv0.18.0-pre.1

cx

The cx codec surface (core; spec/03-approved/core/codec.md §3), reached with [?lib 'cx-stdlib/cx']. Four uniform verbs convert between cx and the CX tree, which is the universal pivot: every conversion is format → tree → format, never format → format. Synthesized from the codec registry, so this surface cannot drift from what the build can actually convert.

cx:parse

[$cx:parse] -> any — Parse cx source TEXT into a CXDM value.

cx:parse-bytes

[$cx:parse-bytes] -> any — Parse cx source BYTES into a CXDM value — the binary half of the codec contract.

cx:emit

[$cx:emit] -> string — Emit a CXDM value as cx TEXT.

cx:emit-bytes

[$cx:emit-bytes] -> bytes — Emit a CXDM value as cx BYTES — the binary half of the codec contract.

cx:serialize

[$cx:serialize] -> string — Render a value as CX text — the lossless image, presentation included.

cx:canonical

[$cx:canonical] -> string — Render a value as STRICT CANONICAL CX text: presentation stripped, data-equivalent to the input. The basis of the content address.

cx:hash

[$cx:hash] -> string — SHA-256 hex digest of a value's strict-canonical bytes — its content address.

cx:diff

[$cx:diff] -> any — Structural difference between two values, as a patch document.

cx:patch

[$cx:patch] -> any — Apply a patch document to a value, answering the patched value.

cx:to-format

[$cx:to-format] -> string — Convert a value to any registered text format by name — the in-program face of the codec registry.

cx:from-format

[$cx:from-format] -> any — Parse text in any registered format by name into a CXDM value.

cx:equal

[$cx:equal] -> bool — Data equality of two values: canonical images compared, presentation ignored.

cx:select

[$cx:select] -> any — Evaluate a path expression against a value and answer what it selects.

cx:carries-err

[$cx:carries-err] -> bool — Report whether RENDERED output text carries an err value anywhere in it — the err-result rule of the run surface, published once (#1351).

      [$cx:carries-err '(1, 4, 9, 16, [err code=shard-offline shard=5], 36)']
    
      true
    

cx:lint

[$cx:lint] -> any — Lint CX source TEXT as cx lint does, answered as data: one [refusal] when the source would be refused (the reader, a directive shape, a [?def] or [?const] body that does not parse), else one [finding] per finding; a clean source answers the empty sequence (cx-private#1812).