format

Emit CX values back to CX text in four forms: canonical, pretty, compact, and diff-friendly. Canonical is the byte-stable hash preimage used for hashing, diffing, and content addressing; pretty is human-readable with indentation and wrapping; compact minimizes whitespace for transport; diff-friendly is a version-stable, one-element-per-line form for snapshots and version control. This is CX-to-CX text only — cross-format conversion lives in modules like json and csv. Every form round-trips: parsing the output is structurally equal to the original value.

format:canonical

[$format:canonical] -> string — Emit the byte-stable canonical form of a value — the hash preimage for content addressing.

format:pretty

[$format:pretty] -> string — Emit a human-readable form with indentation and line wrapping; not version-stable.

            [?lib 'cx-stdlib/format']
[$format:pretty [user]]
          
            '[user]'
          

format:compact

[$format:compact] -> string — Emit a minimum-whitespace form for transport over text channels.

            [?lib 'cx-stdlib/format']
[$format:compact [a [b [c]]]]
          
            '[a [b [c]]]'
          

format:pretty-with-opts

[$format:pretty-with-opts] -> string — Pretty-print with an options map controlling indent, line width, attribute sorting, and depth.

            [?lib 'cx-stdlib/format']
[$format:pretty-with-opts [a [b [c]]] {indent: "    "}]
          
            '[a [b [c] ] ]'
          

format:canonical-with-context

[$format:canonical-with-context] -> element — Emit the canonical text together with its derived hash, length, and token count.

            [?lib 'cx-stdlib/format']
[?let [= $r [$format:canonical-with-context [a 1]]] $r@length]
          
            5
          

format:diff-friendly

[$format:diff-friendly] -> string — Emit a version-stable, one-element-per-line form with sorted attributes for snapshots and diffs.

            [?lib 'cx-stdlib/format']
[$format:diff-friendly [user role="admin" id="7"]]
          
            '[user id="7" role="admin"]'
          

format:emit-stream

[$format:emit-stream] -> [sequence string] — Emit a value as a sequence of chunks whose concatenation equals pretty-with-opts.

            [?lib 'cx-stdlib/format']
[$format:emit-stream [user] {}]
          
            ('[user]')