Form-shape decomposition: semantic structure of Clojure special forms.
Decomposes a call's args into a vector of [slot-name value] pairs that formatters can apply layout opinions to. A decomposer returns nil when the form has no special structure — the printer falls back to plain-call rendering.
Slot vocabulary (the contract between form-shape and printer/style):
:name identifier being defined (defn, def, deftest, catch-binding) :doc docstring :params parameter vector :dispatch-val multimethod dispatch value; catch-exception class :dispatch-fn multimethod dispatch fn; condp pred :test if/when condition :expr case/condp/threading target :bindings let-style pair binding vector (rendered with columnar layout) :as-name as-> binding name :clause test/value pair (value is a [test value] 2-tuple) :arity complete single-arity form ([params] body+) :default case/condp default expression :body ordinary body expression
Slots are emitted in source order; style maps opine on slot names to choose head-line vs body placement and open-paren spacing.
Each decompose-* helper below takes the call's args and returns a
vector [[slot-name value] ...] in the shape described in its
docstring. Returning nil from a decomposer signals the args do not
match — decompose then falls through to structural inference (if
enabled) or to plain-call rendering.
Form-shape decomposition: semantic structure of Clojure special forms. Decomposes a call's args into a vector of [slot-name value] pairs that formatters can apply layout opinions to. A decomposer returns nil when the form has no special structure — the printer falls back to plain-call rendering. Slot vocabulary (the contract between form-shape and printer/style): :name identifier being defined (defn, def, deftest, catch-binding) :doc docstring :params parameter vector :dispatch-val multimethod dispatch value; catch-exception class :dispatch-fn multimethod dispatch fn; condp pred :test if/when condition :expr case/condp/threading target :bindings let-style pair binding vector (rendered with columnar layout) :as-name as-> binding name :clause test/value pair (value is a [test value] 2-tuple) :arity complete single-arity form ([params] body+) :default case/condp default expression :body ordinary body expression Slots are emitted in source order; style maps opine on slot names to choose head-line vs body placement and open-paren spacing. Each `decompose-*` helper below takes the call's args and returns a vector `[[slot-name value] ...]` in the shape described in its docstring. Returning nil from a decomposer signals the args do not match — `decompose` then falls through to structural inference (if enabled) or to plain-call rendering.
(decompose registry head args)Look up the decomposer for head in the given registry and apply it
to args. Returns a vector of [slot-name value] pairs in source
order, or nil if no decomposer is registered or the decomposer
rejects the shape.
The registry is passed in explicitly so that each lang supplies its
own form-shape vocabulary (see meme-lang.form-shape/registry for
the meme-lang built-in). When registry is nil — e.g. a bare call
to printer/to-doc without a lang in play — every head is treated
as having no shape.
A registry may opt into structural fallback by carrying a metadata
key ::fallback-fn — a function (fn [head args] → slots). When
the direct lookup misses, the fallback is consulted; this lets user
macros with a defn- or let-like shape inherit layout without being
registered. See with-structural-fallback.
Look up the decomposer for `head` in the given registry and apply it to `args`. Returns a vector of [slot-name value] pairs in source order, or nil if no decomposer is registered or the decomposer rejects the shape. The registry is passed in explicitly so that each lang supplies its own form-shape vocabulary (see `meme-lang.form-shape/registry` for the meme-lang built-in). When `registry` is nil — e.g. a bare call to `printer/to-doc` without a lang in play — every head is treated as having no shape. A registry may opt into structural fallback by carrying a metadata key `::fallback-fn` — a function `(fn [head args] → slots)`. When the direct lookup misses, the fallback is consulted; this lets user macros with a defn- or let-like shape inherit layout without being registered. See `with-structural-fallback`.
Built-in form-shape decomposers, keyed by head symbol.
Built-in form-shape decomposers, keyed by head symbol.
(with-structural-fallback registry)Return a registry (same entries) that uses structural inference when
no entry matches a given head. Users of the returned registry get
automatic layout for user macros whose shape resembles defn
(name + params) or let (bindings vector).
Return a registry (same entries) that uses structural inference when no entry matches a given head. Users of the returned registry get automatic layout for user macros whose shape resembles `defn` (name + params) or `let` (bindings vector).
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |