02 Schemas and contracts

A schema describes which values an operation accepts. A schema is a plain value, a function, any or never, or an operator form, and each form has one meaning wherever it is written. Compound schemas use meet to require every constraint and join to require at least one; Schema algebra explains their construction and simplification. Schemas are ordinary DUST values. Checking one does not convert a value, add defaults, or attach a permanent type to it.

Use this chapter for schema construction, validation, defaults, generation, and saved definitions. Function contracts connect schemas to callable boundaries and generated tests. Ordinary type predicates and conversions remain in Types.

2.1. Choose an operation

Task Operation
Test whether a value matches schemas/valid?
Select a branch and capture matching values schemas/match
Construct a value from determined fields and defaults schemas/materialize
Generate a value from a schema and a seeded generator schemas/fakerize
Test a function with generated cases and replay failures schemas/check
Explain a mismatch with schema and candidate paths schemas/explain
Reconstruct an owned saved definition schemas/load
Intersect or unite schema constraints schemas/meet, schemas/join
Simplify a schema value schemas/simplify

Start with the required fields of a value. A shape such as {pilot string? spice int?} requires those fields and permits extra fields. Write [optional string?] as the value of a field that can be absent, and [maybe string?] for a value that can be null. Use [... int?] for a list of integers and [map-of int?] for a map with integer values. A scalar schema, including a string, matches that literal value.

any accepts every value and never accepts none. map? and {} accept every map. A function is a schema: int?, positive? and chars/letter? accept the values for which they return true. See Custom predicates to define your own checks. Unknown names, impure predicates, and malformed descriptions are errors, not successful checks. schemas/valid? below gives the full rules.

2.2. Named definitions

The top-level form (defschema name description) binds a named schema. The body can refer to its own name for recursive child values. A named definition keeps the predicates it selected and its namespace revision. Export and import it through ordinary namespace files; no separate schema registry is required.

A named schema keeps the native kind of its description. A named integer is still an integer. Saved definitions preserve source and finite reference graphs, excluding captured runtime state. Reading that data does not execute it; loading it is an explicit operation.

2.3. schemas/valid?

Function

(schemas/valid? schema value) → boolean

Tests a value against a schema without converting it. A schema is one of four things:

  1. A plain value. A scalar or a tagged value accepts only an equal value. A map is an open shape: it accepts every map that has its fields, with values that its field schemas accept. A list is positional: one schema for each position, and the same length.
  2. A function. It accepts a value when calling it on that value returns true. false, another result, or an ordinary error rejects the value. Exhausted resources or cancellation stop the check, so [not S] never accepts a value because the check of S stopped. The function must be pure.
  3. any or never (also ⊤ and ⊥), which accept every value and no value.
  4. An operator form: a list whose first element is a schema operator. The operators are meet, join, not, maybe, map-of, count, error, default and is. An operator is a marker, not a function. Only its schema operands are read as schemas; the arguments of is and default are values.

The kind predicates are schemas for the value kinds: null?, boolean?, int?, float?, number?, string?, template?, bytes?, bitset?, list?, map?, fn?, local?, const?, jsonptr?, uuid?, utc?, duration?, link?, hash?, regex?, regex-matcher?, peg?, invoke?, quote?, quasiquote?, unquote?, unquote-splicing?, tagged?, error?, and the packed math kind predicates v2?, v3?, v4?, m22?, m33?, m44?, quat?, aabb?, ray?, sphere?, plane?, triangle? and frustum?, and the packed vector kind predicates vf? and vi?. Kinds are exact: int? accepts no float, and tagged? accepts no error. true, false and null are literals. A kind is an ordinary name, so a local binding with the same name hides it.

DUST
(schemas/valid? int? 80)  // => true

A map has no reserved keys: value, key and bind, and the operator names, are ordinary field names. Each described field is required, and extra fields are allowed, so adding a field to a shape only narrows it.

A tag in a schema position names predicates. The name t reads as the builtin t when it ends in ?, and as the builtin t? when it does not. Thus <string> and <string?> are both string?, and {name <string>} is {name string?}. A tag with two or more names is their meet, and a negated name is a not: {age <int? math/even?>} and {age <int math/even>} are {age [meet int? math/even?]}, and {nick <!null?>} is {nick [not null?]}. Only builtins are read. A local function with the same name does not change the meaning of the tag. A tag whose name has no builtin is #err <invalid schema>, and the message names the tag: <nope> gives "<nope> has no nope? predicate". JSON writes <string> as {"string": true}, which is the same value, so a schema in JSON or in host data reads the same way.

A tag is a map whose members are all true or false. Thus the map {active true} is the tag <active>, and it is an invalid schema because there is no active? builtin. To require a field to be true, write {active [is = true]}. A map that has tags and other fields, such as {<active> name string?}, is a shape: it requires active to be true and name to be a string. When schemas/simplify or schemas/meet reduces each field of a shape to a boolean, it writes each field as [is = b], so the result stays a shape.

DUST
(schemas/valid? {name string?} {age 23 name "Chani"})  // => true
(schemas/valid? {name string?} {age 23})  // => false
(schemas/valid? [int? string?] [80 "melange"])  // => true
(schemas/valid? {value int?} {value 42})  // => true
DUST
(schemas/valid? {active [is = true]} <!active>)  // => false
DUST
(defschema Pilot {name <string> age [optional <int? !float>]})  // => Pilot
(defn greet [<name>] [{name <string>} => <string>] (str "Hello " name))  // => greet
{bare [(schemas/valid? <string> "Ada") (schemas/valid? <string?> "Ada") (schemas/valid? <string> 1)]
 field [(schemas/valid? {name <string>} {name "Ada"}) (schemas/valid? {name <string?>} {name "Ada"})
        (schemas/valid? {name <string>} {name 1})]
 simplified (schemas/simplify {name <string> nick <string?>})
 group [(schemas/valid? {age <int? math/even?>} {age 4}) (schemas/valid? {age <int? math/even?>} {age 3})
        (schemas/valid? {age <int math/even>} {age 4}) (schemas/valid? {age <int math/even>} {age 4.0})]
 group-simplified (schemas/simplify <int math/even>)
 negated [(schemas/valid? {nick <!null?>} {nick "Usul"}) (schemas/valid? {nick <!null?>} {nick null})
          (schemas/valid? {nick <!null?>} {})]
 negated-simplified (schemas/simplify <!null>)
 nested [(schemas/valid? {pilot {age <int>}} {pilot {age 23}}) (schemas/valid? {pilot {age <int>}} {pilot {age "23"}})]
 positions [(schemas/valid? [<int> <string>] [1 "a"]) (schemas/valid? [... <int>] [1 2 "a"])
            (schemas/valid? [map-of <string> <int>] {a 1}) (schemas/valid? [maybe <string>] null)
            (schemas/valid? [count <int>] [1 2]) (schemas/valid? [not <int>] 1)
            (schemas/valid? {nick [optional <string>]} {})]
 mixed [(schemas/valid? {<active> name <string>} {active true name "Ada"})
        (schemas/valid? {<active> name <string>} {active false name "Ada"})]
 true-field [(schemas/valid? {active [is = true]} {active true}) (schemas/valid? {active [is = true]} {active false})]
 error-payload [(schemas/valid? [error <division>] (/ 1 0)) (schemas/valid? [error <division>] (+ 1 "a"))
                (schemas/valid? [error <invalid schema>] (schemas/valid? <nope> 1))
                (schemas/valid? [error {<invalid schema> message string?}] (schemas/valid? <nope> 1))]
 shared-payload (let [division <division> number <int>]
                  [(schemas/valid? [join number [error division]] (/ 1 0)) (schemas/valid? [join number [error number]] 3)
                   (schemas/valid? [join number [error number]] "3")])
 unknown (schemas/valid? <nope> 1)
 unknown-negated (schemas/valid? <!nope> 1)
 unknown-field (schemas/valid? {name <nope>} {name "Ada"})
 unknown-group (schemas/valid? <int nope> 1)
 no-active (schemas/valid? <active> {active true})
 builtins-only (let [active? (fn [value] true)] (schemas/valid? <active> 1))
 explain (schemas/explain {name <string> age <int? math/even?>} {name 1 age 3})
 meet (schemas/meet <int> <math/even>)
 materialize (schemas/materialize {name [meet <string> [default "Ada"]] nick [optional <string>]})
 fakerize (let [a (random/seeded 7) b (random/seeded 7) value (schemas/fakerize a {age <int> name <string>})]
            [value (= value (schemas/fakerize b {age int? name string?}))])
 match (map (fn [value] (schemas/match value ({name [bind n <string>]} n) (any "none")))
            [{name "Ada"} {name 1}])
 definition [(schemas/valid? Pilot {name "Ada" age 3}) (schemas/valid? Pilot {name "Ada" age 3.0})
             (schemas/valid? Pilot {name 1})]
 contract [(greet {name "Ada"}) (greet {name 1})]
 contract-error (let [safe (fn [x] [<int> => <error>] (/ x 0))] (errors/message (safe 1)))
 callable (let [wide ((fn [callback] [<fn> => [<number> => <int>]] callback) (fn [value] 1))
                apply-one (fn [f] [[<int> => <int>] => <int>] (f 1))]
            [(schemas/valid? [int? => number?] wide) (schemas/valid? [<int> => <number>] wide)
             (schemas/valid? [<string> => <number>] wide) (apply-one (fn [x] (+ x 1)))
             (apply-one (fn [x] "one"))])}
// => {bare [true true false]
//     builtins-only #err {<invalid schema>
//                         message "<active> has no active? predicate"}
//     callable [true
//               true
//               false
//               2
//               #err {<contract result>
//                     message "function contract result mismatch"}]
//     contract [
//       "Hello Ada"
//       #err {<contract input>
//             message "function contract input mismatch"}]
//     contract-error "division by zero"
//     definition [true false false]
//     error-payload [true false true true]
//     explain #err {<schema-mismatch>
//                   errors [{in /age
//                            message "predicate rejected the value"
//                            path /age/2
//                            schema #builtin "math/even?"
//                            value 3}
//                           {in /name
//                            message "predicate rejected the value"
//                            path /name
//                            schema #builtin "string?"
//                            value 1}]
//                   message "value does not match schema"
//                   schema {age [#builtin "meet" #builtin "int?" #builtin "math/even?"]
//                           name #builtin "string?"}
//                   value {age 3
//                          name 1}}
//     fakerize [{age -443 name ""} true]
//     field [true true false]
//     group [true false true false]
//     group-simplified [#builtin "meet" #builtin "int?" #builtin "math/even?"]
//     match ["Ada" "none"]
//     materialize {name "Ada"}
//     meet [#builtin "meet" #builtin "int?" #builtin "math/even?"]
//     mixed [true false]
//     negated [true false false]
//     negated-simplified [#builtin "not" #builtin "null?"]
//     nested [true false]
//     no-active #err {<invalid schema>
//                     message "<active> has no active? predicate"}
//     positions [true false true true true false true]
//     shared-payload [true true false]
//     simplified {name #builtin "string?"
//                 nick #builtin "string?"}
//     true-field [true false]
//     unknown #err {<invalid schema>
//                   message "<nope> has no nope? predicate"}
//     unknown-field #err {<invalid schema>
//                         message "<nope> has no nope? predicate"}
//     unknown-group #err {<invalid schema>
//                         message "<nope> has no nope? predicate"}
//     unknown-negated #err {<invalid schema>
//                           message "<!nope> has no nope? predicate"}}

Openness permits extra fields; it does not make described fields optional. For example, {name string?} rejects {} and accepts {name "Chani" extra 1}.

Whether a field can be missing is a property of the field, not of its value. Write [optional S] as the value of a field, and nowhere else. [maybe S] is a schema: it accepts what S accepts, and null. Thus {nick [optional string?]} accepts {} and rejects {nick null}, and {nick [maybe string?]} rejects {} and accepts {nick null}. A field that can be missing or null is [optional [maybe S]].

DUST
(schemas/valid? {name [optional [maybe string?]]} {})  // => true
(schemas/valid? {name [optional [maybe string?]]} {name null})  // => true
(schemas/valid? {items [optional [maybe [... int?]]]} {items [1 2]})  // => true

A list schema is positional: [int? string?] accepts a list of one integer and one string. ... repeats the schema immediately after it zero or more times, so [... int?] accepts any number of integers. A prefix and a suffix can surround the repeated section. A trailing ... accepts any remaining elements. A list schema can contain one .... list? accepts every list, and [] accepts only the empty list.

DUST
(schemas/valid? [... int?] [1 2 3])  // => true
(schemas/valid? [string? ... int? string?] ["head" 1 2 "tail"])  // => true
(schemas/valid? [string? ...] ["head" 1 null])  // => true

[map-of V] accepts a map whose values V accepts. [map-of K V] also checks each key with K. All map keys are strings, so write K only when it says more than that. A map with no entries satisfies its entry constraints; a value that is not a map does not. A dictionary and a shape combine with meet: [meet [map-of int?] {total int?}] requires an integer total and integer values. Nest the forms directly: [... [... int?]] describes a list of integer lists, and [map-of [... int?]] a map of integer lists.

DUST
(schemas/valid? [map-of int?] {melange 80 water 12})  // => true
(schemas/valid? {foo [... int?]} {foo [1 2]})  // => true
(schemas/valid? [map-of [... int?]] {melange [80 90] water []})  // => true

[is f arg...] accepts a value x when (f x arg...) returns true. It is the one way to call a function with extra arguments, so bounds and equality use it too: [is < 5], [is >= 2.0] and [is = [1 2]]. With a builtin comparison it is a bound, which simplification and generation read. Strings and templates compare as text. [is = v] matches the value v exactly, unless v is an error. [is ! 3]= rejects "a", because != fails on mixed types, but [not [is = 3]] accepts it.

DUST
(schemas/valid? [is >= 18] 21)  // => true
(schemas/valid? [is >= "A"] "Bob")  // => true
(schemas/valid? [is = [1 2]] [1 2 3])  // => false

[count S] checks the number of elements in a list or map, bytes in a byte string, or Unicode code points in a string or template. The count must match S; other kinds do not match. count is a marker in a schema; (count xs) and :count still reach the function.

DUST
(schemas/valid? [count [is >= 3]] [1 2 3])  // => true
(schemas/valid? [count [is = 2]] "éé")  // => true

Use [int?] when exactly one integer is required, and [is = [1 2]] to match a literal list.

[not S] accepts exactly the values that S rejects; it is a single alternative and carries no defaults. [error S] accepts an error whose payload S accepts, so [error <division>] accepts every error tagged division. The operand of error is compared with the payload as data, so a tag in it is not a predicate: [error {<invalid schema> message string?}] accepts an invalid-schema error that has a string message. error? accepts any error.

In a schema, these values have their own meaning and are never read as literals: a function; an error value; an operator, optional, bind, any, never, ... and =>; a name or a quoted form; a list that starts with an operator or contains ... or =>; and any map or list that contains one of these. An error value nested in a schema, or an operator anywhere but the head of a list, is an invalid schema. An unbound name evaluates to an error value, so a misspelled predicate such as {age itn?} is #err <invalid schema>. An error passed as the whole schema argument is the result of the call.

DUST
(schemas/meet int? string?)  // => #builtin "never"
(schemas/valid? int? {int true})  // => false
(let [int? (fn [v] false)] (schemas/valid? int? 8))  // => false
(schemas/valid? [not int?] "x")  // => true
(schemas/valid? [not [not int?]] 3)  // => true
(schemas/meet int? [not int?])  // => #builtin "never"
(let [positive? (fn [x] (> x 0))] [(schemas/valid? positive? "x") (schemas/valid? [not positive?] "x")])  // => [false true]
(schemas/valid? {items :count} {items [1 2]})  // => false
[(schemas/valid? {age itn?} {age 3})]
// => [#err {<invalid schema>
//           message "an error value is not a schema"}]
(schemas/valid? {default 5 not true} {default 5 not true})  // => true
[(schemas/valid? {mode not} {mode 1})]
// => [#err {<invalid schema>
//           message "schema operator is not valid in this position"}]
(schemas/valid? {nick [optional string?]} {})  // => true
(schemas/valid? {nick [optional string?]} {nick null})  // => false
(schemas/valid? {nick [maybe string?]} {})  // => false
(schemas/valid? {nick [maybe string?]} {nick null})  // => true
(schemas/valid? {nick [not null]} {})  // => false
(schemas/match {} ({nick [optional [bind nick string?]]} nick))  // => null
(schemas/valid? [meet [map-of int?] {total int?}] {total 5 a 1})  // => true
(schemas/valid? [meet [map-of int?] {total int?}] {a 1})  // => false
(schemas/valid? [is != 3] "a")  // => false
(schemas/valid? [not [is = 3]] "a")  // => true
(schemas/valid? {age #builtin "int?"} {age 3})  // => true
[(schemas/valid? (documents/value (encoding/decode "dust" "{age int?}")) {age 3})]
// => [#err {<invalid schema>
//           message "a name or a quoted form is not a schema"}]
(schemas/explain {a int? b (fn positive? [x] (> x 0)) c (fn [x] (> x 0))} {a "x" b -1 c -1})
// => #err {<schema-mismatch>
//          errors [{in /a
//                   message "predicate rejected the value"
//                   path /a
//                   schema #builtin "int?"
//                   value "x"}
//                  {in /b
//                   message "predicate rejected the value"
//                   path /b
//                   schema (fn positive? [x] (> x 0))
//                   value -1}
//                  {in /c
//                   message "predicate rejected the value"
//                   path /c
//                   schema (fn [x] (> x 0))
//                   value -1}]
//          message "value does not match schema"
//          schema {a #builtin "int?"
//                  b (fn positive? [x] (> x 0))
//                  c (fn [x] (> x 0))}
//          value {a "x"
//                 b -1
//                 c -1}}
DUST
(schemas/valid? <active> {active true name "Ada"})
// => #err {<invalid schema>
//          message "<active> has no active? predicate"}
(schemas/valid? {active [is = true]} {active true})  // => true
(schemas/valid? (schemas/meet {active [is = true]} {name string?}) {active true name "Ada"})  // => true
(schemas/valid? {} 42)  // => false
(schemas/valid? {} {a 1})  // => true
(schemas/valid? any 42)  // => true
(schemas/valid? [] [1])  // => false
(schemas/valid? [] [])  // => true
(let [f (fn [x] x)] (schemas/valid? f f))  // => false
(let [f (fn [x] x)] (schemas/valid? [is = f] f))  // => true
(let [f (fn [x] x)] [(schemas/valid? f true) (schemas/valid? f 3)])  // => [true false]
(schemas/valid? [error <division>] (/ 1 0))  // => true
(schemas/valid? [error <division>] (+ 1 "a"))  // => false
(schemas/valid? error? (/ 1 0))  // => true

The top-level form (defschema name description) binds a named description. Its body can refer to the name being defined. For example, each house below has a required name and a list of child houses. A recursive leaf has an empty children list; omitting the children field does not match.

DUST
(defschema House {children [... House] name string?})  // => House
(schemas/valid? House {children [{children [] name "Paul"}] name "Atreides"})  // => true

Each recursive cycle must descend into a child value. A definition such as (defschema Loop [meet Loop]) is invalid because it never reaches a child. Checking a cyclic candidate terminates and rejects it. Sharing a child between two finite branches is allowed.

A named description keeps the predicates and namespace revision selected when it was defined, including qualified imports. Replacing a namespace later does not change existing descriptions. Ordinary collection mutation still changes the description itself; the next check uses its current contents. For example, (defschema Alias House) gives the existing description another name without changing its recursive references or predicates.

A named scalar keeps its native value kind. Its definition provenance follows bindings, direct returns, and copies. A computation makes a new value without that provenance: Answer below snapshots as (defschema Answer 42), while (+ Answer 0) snapshots as plain 42.

DUST
(defschema Answer 42)  // => Answer
(documents/value (documents/from-value Answer))  // => (defschema Answer 42)
(documents/value (documents/from-value (+ Answer 0)))  // => 42

A schema read from plain data is not evaluated. A kind or an operator is written there as #builtin "int?" or #builtin "meet", and in JSON as {"#builtin": "int?"}. A bare name in plain data is still a name, so it is an invalid schema. A predicate that a program defines cannot be named in plain data; a saved definition carries its functions. A document snapshot writes a builtin function in a schema as its #builtin form.

DUST
(documents/value (documents/from-value [>= 3]))  // => [#builtin ">=" 3]

2.4. schemas/match

Special Form

(schemas/match candidate (pattern [when guard] body...) ...)

Evaluates candidate once. It checks branches in source order and selects the first matching pattern with a true guard.

A [bind name S] pattern captures the candidate after S matches it. For example, [bind amount int?] checks an integer and names it amount inside the selected branch. [bind name] captures its candidate without a check. The capture name is not evaluated. A capture exists only after the complete pattern matches. bind belongs to match patterns; it is invalid in a schemas/valid? description.

DUST
(schemas/match 80 ([bind amount int?] (+ amount 1)))  // => 81

Capture names must be declared in that branch's pattern source. A computed descriptor cannot introduce a new capture name. Dynamic patterns without captures remain valid.

An absent optional field captures null. Repeated captures keep these slots, preserving their list shape.

Captures retain named-schema definition provenance without changing native value kinds. This also applies to values collected by repeated captures.

A repeated list constraint collects its capture values in order. Nested repetitions produce nested lists, including empty lists for zero matches.

Map keys are always strings, so capturing a key needs no string check. Collection captures bind the same lists and maps as the values they match. For {a 1 b 2}, the pattern [map-of [bind keys] [bind values int?]] binds keys to {a "a" b "b"} and values to {a 1 b 2}. Both captures use the original input keys; their result does not depend on traversal order. Empty maps yield empty maps.

A list schema such as [... [bind values int?]] captures an ordered list, including an empty list for empty input. Nested collection captures preserve each map or list layer. Failed branches discard all partial captures.

The optional guard can use branch captures. It must be pure and return a boolean. False or an ordinary error skips the branch. Calling a map or list reads a path and is permitted as a pure guard.

Patterns and guards use ordinary lexical name resolution. Pure functions from the current session or imported namespaces can be guards; function references whose purity cannot be established are invalid guards.

Resource exhaustion, cancellation, and other operation failures stop the match. They do not select a later branch.

An impure guard or a nonboolean guard is invalid. The engine rejects an impure guard before its effect occurs.

Only the selected body runs. Its forms run in order, and schemas/match returns the last result. No matching branch returns null.

Use an any branch for an explicit fallback. Separate branches can use the same capture name, but one pattern cannot contain duplicate names.

Captures are invalid inside join and not. Use separate branches when each alternative needs captures or source-order selection.

DUST
(schemas/match
  {pilot "Chani" reserve 50 spice 80}
  ({pilot [bind pilot string?]
    reserve [bind reserve int?]
    spice [bind amount int?]}
    [when (> amount reserve)]
    ~",pilot can release ,(- amount reserve)")
  (any "Keep the reserve"))  // => "Chani can release 30"
(schemas/match
  [{spice 80} {spice 90}]
  ([... {spice [bind amounts int?]}]
    amounts))  // => [80 90]
(schemas/match
  {melange 80 water 12}
  ([map-of [bind keys] [bind values int?]]
    [keys values]))  // => [{melange "melange" water "water"} {melange 80 water 12}]

2.5. schemas/materialize

Function

(schemas/materialize schema) → value
error

Creates a concrete value only when the schema determines one. It can select a literal, a forced value, or a default preference. It does not convert values. Defaults do not restrict accepted values; schemas/valid? ignores them. Write a preference beside its constraint, for example [meet int? [default 8080]].

A schema with or without defaults is materialized by the same rules. Each join alternative keeps its own constraints and defaults, and an alternative that accepts no value takes no part, so schemas/meet distributes over schemas/join: [meet int? [join string? 0]] materializes to 0.

DUST
(schemas/materialize [join 1 2])
// => #err {<invalid value>
//          message "schema does not determine a value"}
(schemas/materialize [meet int? [join string? 0]])  // => 0
(schemas/materialize (schemas/meet int? (schemas/join string? 0)))  // => 0
(schemas/materialize (schemas/join (schemas/meet int? string?) (schemas/meet int? 0)))  // => 0
(schemas/materialize [join 0 [meet string? int?]])  // => 0
(schemas/materialize (schemas/simplify [join 0 [meet string? int?]]))  // => 0
(schemas/materialize {port [meet int? [join "auto" 80]]})  // => {port 80}
(schemas/materialize {settings map?})  // => {settings {}}
(schemas/materialize [map-of int?])  // => {}
(schemas/materialize [meet string? map?])
// => #err {<invalid value>
//          message "schema does not determine a value"}

Materialization resolves defaults after all hard constraints. A default is read in pieces. A map default gives one piece for each field and one piece that says a map exists. A list default gives one piece for each position and one piece for its length. A constraint that excludes a piece gives it up. A constraint that fixes the kind of a position, such as map?, a shape or a literal, also gives up the pieces below it that need another kind. A fixed value, written as a literal or as [is = x], wins over a default at its position. A function at a position is a predicate, not a fixed value. Compatible pieces at separate map fields or list positions combine.

DUST
(defschema Q [meet [is = 5] [default 0]])  // => Q
(schemas/materialize [meet [is = 5] [default 0]])  // => 5
(schemas/materialize [meet 5 [default 0]])  // => 5
(schemas/materialize [is = 5])  // => 5
(schemas/materialize Q)  // => 5
(schemas/materialize (schemas/load (documents/value (documents/from-value Q))))  // => 5
(schemas/materialize [meet [is = [1 2]] [default [0 0]]])  // => [1 2]
(schemas/materialize {port [meet int? [is = 443] [default 80]]})  // => {port 443}

Fixed map and list values remain unchanged while deeper constraints are checked. A contradictory field or position returns an error and does not change the original value or schema.

DUST
(def original {x 1})  // => original
[(schemas/materialize [meet [is = original] {x 2}]) original]
// => [#err {<invalid value>
//           message "schema does not determine a value"}
//     {x 1}]
(def nested {a {x 1}})  // => nested
[(schemas/materialize [meet [is = nested] {a {x 2}}]) nested]
// => [#err {<invalid value>
//           message "schema does not determine a value"}
//     {a {x 1}}]
(def sequence [1 2])  // => sequence
[(schemas/materialize [meet [is = sequence] [3 4]]) sequence]
// => [#err {<invalid value>
//           message "schema does not determine a value"}
//     [1 2]]
(def wrapped {a [1 2]})  // => wrapped
[(schemas/materialize [meet {a [is = (get wrapped "a")]} {a [3 4]}]) wrapped]
// => [#err {<invalid value>
//           message "schema does not determine a value"}
//     {a [1 2]}]
[(schemas/materialize [meet [is = original] {x 1}]) original]  // => [{x 1} {x 1}]
(schemas/materialize [meet [is = {a 1}] [default {a 1}] [default {a 2}]])  // => {a 1}
(schemas/materialize [meet [is = {a 1}] [default {a 1 b 2}] [default {a 1 b 3}]])  // => {a 1}
(schemas/materialize [meet [is = {a {b 1}}] [default {a {b 1}}] [default {a {b 2}}]])  // => {a {b 1}}

A default is identified by its position and value. Equal defaults at one position are one default, also when they are written separately or restored after save and load.

DUST
(def D [default 8080])  // => D
(def S [join [meet D int?] [meet D "auto"]])  // => S
(def R (documents/value (documents/from-value S)))  // => R
(schemas/materialize [join [meet [default 8080] int?] [meet [default 8080] "auto"]])  // => 8080
(= R [#builtin "join" [#builtin "meet" [#builtin "default" 8080] #builtin "int?"] [#builtin "meet" [#builtin "default" 8080] "auto"]])  // => true
(schemas/materialize S)  // => 8080
(schemas/materialize R)  // => 8080
(schemas/materialize
  [join [meet {port int?} [default {port 8080}]] [meet {port "auto"} [default {port 8080}]]])  // => {port 8080}
(schemas/materialize [join [meet [default [1 2]] [int? int?]] [meet [default [1 2]] [1 3]]])  // => [1 2]

A join keeps its alternatives and their defaults separate. An alternative that accepts no value takes no part: a literal or [is = x] that another constraint at its position rejects removes its alternative. One alternative beats another when, among the defaults that applied to both, it gave up a strict subset of what the other gave up. Materialization uses only the preferred alternatives, which no other alternative beats.

DUST
(schemas/materialize [meet "auto" [join [is >= 0] [default 0]]])  // => "auto"
(schemas/materialize (schemas/meet "auto" (schemas/join [is >= 0] [default 0])))  // => "auto"
(schemas/materialize [join [meet 5 [is < 3]] [meet int? [default 1]]])  // => 1
(schemas/materialize [join [meet [is = 5] [is < 3]] [meet int? [default 1]]])  // => 1
(schemas/materialize [join [meet 2 [is < 3]] [meet int? [default 1]]])
// => #err {<invalid value>
//          message "schema does not determine a value"}
(schemas/materialize [join [meet {port int?} 5] [meet int? [default 1]]])  // => 1
(schemas/materialize [join [meet [int? int?] "auto"] [meet string? [default "a"]]])  // => "a"

Defaults that disagree at one position in a preferred alternative, or in two preferred alternatives that share an accepted value, return conflicting defaults as an invalid-value error. A beaten alternative cannot cause this error. Defaults of different kinds at one position, such as a scalar and a map, or a map and a list, disagree.

DUST
(def D1 [default 1])  // => D1
(schemas/materialize [join [meet int? D1] [meet [is >= 5] D1 [default 7]]])  // => 1
(schemas/materialize
  [join [meet int? [default 1]] [meet [is >= 5] [default 1] [default 7] [default 8]]])  // => 1
(schemas/materialize [join [meet int? [default 1]] [meet [is >= 0] [default 2]]])
// => #err {<invalid value>
//          message "conflicting defaults"}
(schemas/materialize [join [meet int? [default 1]] [meet string? [default "a"]]])
// => #err {<invalid value>
//          message "schema does not determine a value"}
DUST
(schemas/materialize [meet [default [0 1]] [default {port 0}]])
// => #err {<invalid value>
//          message "conflicting defaults"}
(schemas/materialize [meet [default {port 0}] [default [0 1]]])
// => #err {<invalid value>
//          message "conflicting defaults"}
(schemas/materialize [meet [default 1] [default {port 0}]])
// => #err {<invalid value>
//          message "conflicting defaults"}
(schemas/materialize [meet [default {port 0}] [default 1]])
// => #err {<invalid value>
//          message "conflicting defaults"}
(schemas/materialize [meet map? [default 1] [default {port 0}]])  // => {port 0}
(schemas/materialize [join [meet any [default 1]] [meet any [default {port 0}]]])
// => #err {<invalid value>
//          message "conflicting defaults"}
(schemas/materialize [join [meet int? [default 1]] [meet map? [default {port 0}]]])
// => #err {<invalid value>
//          message "schema does not determine a value"}
(schemas/materialize [meet map? [default {port 0}] [default [0 1]]])  // => {port 0}
(schemas/materialize [meet map? [default [0 1]] [default {port 0}]])  // => {port 0}
(schemas/materialize [meet list? [default [0 1]] [default {port 0}]])  // => [0 1]
(schemas/materialize [meet {port int?} [default [0 1]] [default {port 0}]])  // => {port 0}
(schemas/materialize [meet 5 [default {port 0}]])  // => 5
(schemas/materialize [meet [int? int?] [default {port 0}] [default [0 1]]])  // => [0 1]
(schemas/materialize [meet (fn [x] (map? x)) [default {port 0}] [default [0 1]]])
// => #err {<invalid value>
//          message "schema does not determine a value"}

Materialization returns the most general value of the preferred alternatives. If none is most general, it returns schema does not determine a value. Values are compared by structure, not read as schemas. A value is more general than another when each piece that it states is in the other: an equal scalar, a map with all of its fields, or a list of the same length, position by position. Thus {a 1} is more general than {a 1 b 2}, but [1] is not more general than [1 1], and [] is more general only than [].

DUST
(schemas/materialize {tls [meet boolean? [default false]]})  // => <!tls>
(schemas/materialize {tls [meet boolean? [default true]]})  // => <tls>
(schemas/materialize [join [meet [count [is = 1]] [default [1]]] [meet [1 1] [default [1 1]]]])
// => #err {<invalid value>
//          message "schema does not determine a value"}
(schemas/materialize [join [meet [count [is = 0]] [default []]] [meet [1 2] [default [1 2]]]])
// => #err {<invalid value>
//          message "schema does not determine a value"}
(schemas/materialize
  [join [meet {a int?} [default {a 1}]] [meet {a int? b int?} [default {a 1 b 2}]]])  // => {a 1}
(schemas/materialize
  [join [meet [int? int?] [default [1 2]]] [meet [int? int?] [default [1 3]]]])
// => #err {<invalid value>
//          message "conflicting defaults"}

A default inside optional applies only when the field is present, so it never makes the field present. To prefer a present field, put the default on the enclosing map: [meet {note [optional [maybe string?]]} [default {note "ready"}]] materializes to {note "ready"}, while {note [optional [default "ready"]]} materializes to {}. map?, a shape and a map-of dictionary materialize to {} at any position, because the empty map is the most general map; int? and list? do not determine a value.

A repeated element schema such as [... int?] does not choose a list length. Supply a forced value or default when materializing it. It does not give up the length of a list default, so [meet [... int?] [default [1]] [default [1 2]]] returns conflicting defaults, the same as with list?.

DUST
(schemas/materialize [meet [... int?] [default [1]] [default [1 2]]])
// => #err {<invalid value>
//          message "conflicting defaults"}
(schemas/materialize {tags [meet [... string?] [default []] [default ["viewer"]]]})
// => #err {<invalid value>
//          message "conflicting defaults"}
(schemas/materialize [meet list? [default [1]] [default [1 2]]])
// => #err {<invalid value>
//          message "conflicting defaults"}
(schemas/materialize [meet [... any] [default [1]] [default [1 2]]])
// => #err {<invalid value>
//          message "conflicting defaults"}
(schemas/materialize [meet [... int?] [default [1 2]]])  // => [1 2]
(schemas/materialize {tags [meet [... string?] [count [is = 1]] [default []] [default ["viewer"]]]})  // => {tags ["viewer"]}

A constraint on the whole list also applies to the pieces of a list default. A repeated element schema, [... S], gives up a position whose value it rejects. A count gives up a length it rejects, and a position that no permitted length reaches. Thus [meet [... int?] [count [is < 1]] [default [1]] [default [1 2]]]= materializes to [1]: the count gives up the length 2 and the second position.

DUST
(schemas/materialize [meet [... int?] [count [is <= 3]] [default [1]] [default [1 2]]])
// => #err {<invalid value>
//          message "conflicting defaults"}
(schemas/materialize [meet [... int?] [count [is <= 1]] [default [1]] [default [1 2]]])  // => [1]
(schemas/materialize {v [meet [... int?] [count [is <= 1]] [default [1 2]]]})  // => {v [1]}
(schemas/materialize [meet [... string?] [count [is < 2]] [default ["a" "b"]]])  // => ["a"]
(schemas/materialize {v [meet [... int?] [count [join [is = 0] [is = 1]]] [default [1]] [default [1 2]]]})  // => {v [1]}
(schemas/materialize [meet [... int?] [count [meet [is >= 0] [is <= 1]]] [default [1]] [default [1 2]]])  // => [1]
(schemas/materialize [meet [... int?] [default [1 "a"]]])
// => #err {<invalid value>
//          message "schema does not determine a value"}
(schemas/materialize [meet [... int?] [default [1 "a"]] [default [1 2]]])  // => [1 2]
(schemas/materialize [meet [... int?] [default [{a 1}]] [default [1]]])  // => [1]
(schemas/materialize [meet [... int?] [default [[1]]] [default [1]]])  // => [1]
(schemas/materialize [meet [... [... int?]] [default [[{a 1}]]] [default [[1]]]])  // => [[1]]
(schemas/materialize [meet [... {a int?}] [default [[1]]] [default [{a 1}]]])  // => [{a 1}]
(schemas/materialize [meet [... {a int? b int?}] [default [{a 1}]] [default [{b 2}]]])  // => [{a 1 b 2}]
(schemas/materialize [meet [... [join int? string?]] [default [{a 1}]] [default [1]]])  // => [1]
(defschema IntElement int?)  // => IntElement
(schemas/materialize [meet [... IntElement] [default [{a 1}]] [default [1]]])  // => [1]
(defschema MapElement {a int? b int?})  // => MapElement
(schemas/materialize [meet [... MapElement] [default [{a 1}]] [default [{b 2}]]])  // => [{a 1 b 2}]
(defschema Row [meet {a int?} {b int?}])  // => Row
(schemas/materialize [meet [... Row] [default [{a "x" b 1}]] [default [{a 1 b 1}]]])  // => [{a 1 b 1}]
(schemas/materialize [meet [... [int? int?]] [default [{a 1}]] [default [[1 2]]]])  // => [[1 2]]
(schemas/materialize [meet [... [int? int?]] [default [[1 "x"]]] [default [[1 2]]]])  // => [[1 2]]

A repeated element schema also gives up incompatible container pieces and pieces below them. For example, [meet [... int?] [default [{a 1}]] [default [1]]] gives [1]. Compatible partial map defaults still combine their fields.

A repeated list schema such as [1 ... 2] fixes some positions but not the list length. It needs a fixed value or default to materialize; the shortest accepted list is not more general than longer lists.

DUST
(schemas/materialize [... 1])
// => #err {<invalid value>
//          message "schema does not determine a value"}
(schemas/materialize [1 ... 2])
// => #err {<invalid value>
//          message "schema does not determine a value"}
(schemas/materialize [1 ...])
// => #err {<invalid value>
//          message "schema does not determine a value"}
(schemas/materialize [meet [1 ... 2] [default [1 2 2]]])  // => [1 2 2]
(schemas/materialize [meet [1 ... 2] [is = [1 2]]])  // => [1 2]
(schemas/materialize [meet [1 ... 2] [default [1]]])  // => [1]
(schemas/materialize [meet [1 ... 2] [is = [1]]])  // => [1]
(schemas/materialize [meet [1 ... 2] [default [2]] [default [1]]])  // => [1]
(schemas/materialize [meet [1 ... 2] [default [1 "x"]] [default [1 2]]])  // => [1 2]

Materialization does not call an opaque predicate to search for a value. This reasoning is incomplete by design. An opaque predicate constraint alone does not determine a value. Compatible nested shapes in a meet combine their required fields; different join alternatives do not invent a merged value. After selection, the shared checker runs all applicable predicates on the concrete candidate.

DUST
(schemas/materialize {host "localhost" port [default 8080]})
// => {host "localhost"
//     port 8080}
(schemas/materialize {name [default "Chani"] note [optional [maybe string?]]})  // => {name "Chani"}
(schemas/materialize {port int?})
// => #err {<invalid value>
//          message "schema does not determine a value"}
(schemas/materialize [meet {port [default 8080]} {port [default 9090]}])
// => #err {<invalid value>
//          message "conflicting defaults"}

2.6. schemas/fakerize

Function

(schemas/fakerize generator schema) → value
error
(schemas/fakerize generator schema options) → value
error

Makes a random value that matches schema. The function advances the supplied random generator. Equal generator states and equal schemas produce equal values.

The generator selects join branches, maybe alternatives, optional fields, repeated elements, collection lengths, scalar boundaries, and ordinary scalar values. The default size is 64 choices.

Set size in the options map to use a different budget. The valid range is 1 through 8,192 choices. Recursion, collections, strings, and scalar choices use the same budget.

schemas/fakerize supports exact values, kind predicates, bounds, shapes, positional lists, repetition, count constraints, map-of dictionaries, [error S], defaults, and recursive named schemas. It can construct each native value kind. A not operand constructs nothing; another operand of the same meet builds the value, and the final check filters it.

schemas/fakerize does not call an opaque predicate. When no constructive alternative remains, an opaque predicate returns #err <unsupported generation>. A schema with no accepted values returns #err <impossible generation>. An empty size budget returns #err <exhausted generation>.

Generated values pass the shared checker for their constructive branch before return. Opaque alternatives are never called. Rejected candidates use the same bounded budget.

DUST
(schemas/fakerize (random/seeded 42) [meet int? [is >= 18] [is <= 21]])  // => 18
(schemas/fakerize (random/seeded 42) [meet [... int?] [count [is = 3]]] {size 8})  // => [360 -242 -833]

Guarded recursive schemas use the same budget. The generator selects a terminating collection length before the budget is empty.

2.7. schemas/check

Function

(schemas/check function) → report
error
(schemas/check function options) → report
error

Generates isolated calls from a declared contract or an exact inferred signature. The default options are {seed 0 cases 1000 size 8192}. cases must be from 1 through 1,000,000; size must be from 1 through 8,192 choices per case. A declared contract is an obligation to test, not proof of correct behavior. Approximate inference alone returns <unsupported>.

Each case starts with fresh inputs and function state. Arguments can share collections. Named schema definitions are copied into the check; captured caller state is unsupported. Tested functions cannot access the real filesystem, network, processes, or database. Clock reads use generated times. Seeded random operations retain their deterministic algorithm and record their outputs. Effects without a model return <unsupported> before the body runs.

A report contains status (<passed>, <failed>, or <unsupported>), cases, seed, and failures. Unsupported reports also contain reason. Failures contain minimized inputs, effects, before and after state, diagnostics, origin, and replay. Result mismatches use the shared schema diagnostics. Function values in reports are owned definition data, including builtin names; report publication does not reconstruct a live closure. Passing means the requested generated cases completed; it is not proof for every possible input. A CPU, memory, cancellation, or generation-budget interruption returns an error and cannot become a passing report.

DUST
(schemas/check (fn [amount] [int? => int?] amount) {cases 4 seed 42 size 64})
// => {cases 4
//     failures []
//     seed 42
//     status <passed>}

To reproduce a failure, pass only {replay "BLOB"} as the options map. Do not combine replay with seed, cases, or size. Replay checks the definition, owned schema snapshot, and draw protocol. A changed snapshot returns #err <check mismatch replay>; malformed or non-reproducing traces return an error. Copy the returned blob verbatim.

2.8. schemas/explain

Function

(schemas/explain schema value) → null
error

Returns null when value matches schema. A mismatch returns a structured #err <schema-mismatch> value. An invalid schema returns a separate #err <invalid schema> value.

The top-level error contains schema, value, and errors. Each error entry contains path, in, schema, value, and message. path points into the schema. in points into the candidate. Both fields use JSON Pointers, including (jsonptr "") for the root.

A predicate is shown as it prints: a builtin by its name, such as #builtin "int?", a named function such as (fn positive? [x] ...) with its name, and an anonymous function as its source. An error that a predicate returned is available in cause. When every join branch fails, errors contains diagnostics for each failed branch. Recursive references and nested collections retain their local schema and candidate paths. Successful sibling fields do not produce error entries.

DUST
(schemas/explain {pilot {age int? name string?}} {pilot {age "23" name "Chani"}})
// => #err {<schema-mismatch>
//          errors [{in /pilot/age
//                   message "predicate rejected the value"
//                   path /pilot/age
//                   schema #builtin "int?"
//                   value "23"}]
//          message "value does not match schema"
//          schema {pilot {age #builtin "int?"
//                         name #builtin "string?"}}
//          value {pilot {age "23"
//                        name "Chani"}}}

2.9. schemas/load

Function

(schemas/load definition) → schema

Reconstructs a named schema from definition data returned by documents/value. A self-contained definition is a (defschema name description) source form. A definition that refers to other named schemas or predicate functions uses a finite graph with explicit definition identities and reference bindings. Same-named definitions in different namespaces remain distinct.

The graph records namespace paths and revisions. Its source fields describe the snapshot's current constraints; authored_source metadata retains the original schema code without comments. Loading uses the effective definitions and does not execute the authored-source metadata. Missing references, unsupported captured values, and invalid definition graphs produce errors.

A saved predicate can refer to another named schema. The snapshot records that schema's definition and identity, including scalar and function-valued schemas. Two saved predicates can retain different definitions of the same constant name. Ordinary captured runtime values are unsupported; pass candidate data as arguments instead. Structural schema cycles must descend into child values; a cycle through an opaque function capture is an error.

Literal source forms, such as a quoted (fn [x] true) or (defschema Inner 42), remain data when a definition is loaded. Only the graph's explicit saved function definitions are reconstructed as callable values.

A Document owns its definition data independently of the runtime that made it. Reading or decoding the Document returns data without executing the definition. Use schemas/load with definition data to reconstruct a runtime schema, then use schemas/valid? to check a candidate against that schema. Pass definition data to schemas/load, rather than an opaque Document handle. Publish named namespace schemas with defschema. Loading runs outside namespace initialization.

DUST
(defschema Pilot {name string?})  // => Pilot
(let
  [definition (documents/value (documents/from-value Pilot)) restored (schemas/load definition)]
  (schemas/valid? restored {name "Chani"}))  // => true

2.10. Function contracts and generated checks

A function can put [input-schema ... => result-schema] after its parameter list. Each arity can declare its own contract. Calls check arguments and the returned value. A declaration states an obligation; it does not prove the body. Contract schemas keep the bindings selected when the function is constructed. The function reference describes variadic contracts and checked callbacks.

The compiler also infers signatures from function bodies. An exact signature has matching possible and guaranteed success regions. Unsupported behavior keeps inference approximate. schemas/check tests declared contracts or exact inferred signatures using fresh generated inputs, modeled effects and bounded work. It reports passed, failed or unsupported, with minimized failures and replay. An interrupted run cannot pass. Captured caller state and effects without a supported model are unsupported.

Use stardust test to check a file's functions from the command line. Hosts use the shared schema and signature request methods.

2.11. Database checks and presentation

Queries can explicitly select entities whose complete documents match a schema. Checked transactions validate complete post-patch entities before any facts commit. A patch may omit a required field already present in the entity. One invalid candidate rejects the transaction. These checks do not insert defaults or assign permanent types to database fields.

Encoding can take an explicit schema and presentation hints to choose field order and line layout. Presentation does not change equality, validation or canonical encoding. Schema checking, default materialization, generation, database admission and display remain explicit operations.

2.12. Custom predicates

Define a predicate as a pure function that accepts one candidate and returns true or false. Bind it with let or def, then use it as a schema, alone or with other constraints in a meet. For example, the positive? function below is used in [meet int? positive?]: the candidate must be an integer and satisfy positive?. The standard chars/ predicates are ordinary predicates too. For example, [meet string? chars/letter?] accepts a one-code-point string that is a Unicode letter. PEG patterns use the same predicates directly. Use [not positive?] to require that the predicate rejects the candidate. Any result other than true rejects the candidate, including an ordinary error, so a function never makes a schema invalid by what it returns. An impure predicate is an invalid schema. A predicate is an ordinary value: lexical scope selects it, and a local binding hides a builtin of the same name.

DUST
(let [positive? (fn [value] (> value 0))] (schemas/valid? [meet int? positive?] 80))  // => true

The schema can be computed before the check. A direct schemas/valid? call uses the predicates in scope at the call, and a schema inside a function keeps the predicates of that function's lexical scope.

[is f arg...] calls f with the candidate first, followed by the arguments. A list headed by a function has no special meaning: [positive?] is a positional list of one element.

DUST
(schemas/valid? [is strings/starts-with? "spice/"] "spice/melange")  // => true

Reuse a predicate in a named schema with defschema. The schema retains the predicates selected at its definition. A predicate alone describes a check; it does not tell schemas/materialize or schemas/fakerize how to construct a matching value. See those operations for construction limits.

2.13. Schema algebra: meet and join

A schema describes a set of accepted values. meet takes the intersection: a value must satisfy every operand. join takes the union: a value must satisfy at least one operand. any accepts every value and never accepts none. ⊤ and ⊥ are short forms for any and never.

Write [meet schemas...] or [join schemas...] inside a schema description. Call schemas/meet or schemas/join to construct and simplify a schema value. Both calls accept zero or more operands. An empty meet returns any; an empty join returns never.

Both operations flatten matching combinations, remove duplicate builtin constraints and apply any=/=never identities. They recognize a builtin kind predicate, such as int?, by its function value, not by its name, and so do schemas/simplify, schemas/materialize, schemas/fakerize and schemas/check. Every other function stays opaque: it is retained, not used to discover reductions. A named definition keeps its identity and can remain unsimplified. Results write a builtin function in its plain-data form, such as #builtin "int?", and a marker as #builtin "meet". Defaults are preferences and do not change accepted values. Cyclic combinations are invalid. Normalization has a bounded work budget; exhausting it returns a resource error rather than a partially combined schema.

2.13.1. schemas/meet

Function

(schemas/meet schemas*) → schema

Returns the intersection of its operands. Incompatible builtin constraints reduce to never: (schemas/meet int? string?) and (schemas/meet int? [not int?]) are never. Open shapes without a name meet field by field, so (schemas/meet {active [is = true]} {name string?}) is one shape with both fields. A field stays optional only when it is optional in every shape.

A meet that reduces to a literal keeps its defaults, also a default that the literal excludes: (schemas/meet [default 1] 2) returns [meet 2 [default 1]]. The literal has given up that default, and a later join prefers an alternative that kept it. Thus schemas/meet distributes over schemas/join, and schemas/simplify does not change what a schema materializes.

DUST
(def D [default 8080])  // => D
(def One [default 1])  // => One
(def S [join [meet D int?] [meet D "auto"]])  // => S
(schemas/materialize S)  // => 8080
(schemas/materialize (schemas/simplify S))  // => 8080
(schemas/materialize (schemas/meet D [join int? "auto"]))  // => 8080
(schemas/materialize (schemas/join (schemas/meet D int?) (schemas/meet D "auto")))  // => 8080
(schemas/meet [default 8080] "auto")  // => [#builtin "meet" "auto" [#builtin "default" 8080]]
(schemas/meet [default 1] 2)  // => [#builtin "meet" 2 [#builtin "default" 1]]
(schemas/meet [default 1] 2 int?)  // => [#builtin "meet" 2 [#builtin "default" 1]]
(schemas/meet [default 1] 2 string?)  // => #builtin "never"
(schemas/simplify [meet [default 1] 2])  // => [#builtin "meet" 2 [#builtin "default" 1]]
(schemas/materialize (schemas/join (schemas/meet One 2) [meet int? One]))  // => 1
DUST
(schemas/meet int? 3)  // => 3
(schemas/meet int? string?)  // => #builtin "never"
(schemas/meet)  // => #builtin "any"

2.13.2. schemas/join

Function

(schemas/join schemas*) → schema

Returns a schema accepting values from any operand.

DUST
(schemas/join int? string?)  // => [#builtin "join" #builtin "int?" #builtin "string?"]
(schemas/join int? any)  // => #builtin "any"
(schemas/join)  // => #builtin "never"

2.14. schemas/simplify

Function

(schemas/simplify schema) → schema

Returns a simplified schema without changing its input. It reduces supported combinations at the root and within map fields, lists and collection constraints.

DUST
(schemas/simplify [join [meet int? 3] never])  // => 3
(schemas/simplify {amount [meet int? 3]})  // => {amount 3}
(let [schema [meet int? 3] result (schemas/simplify schema)] [result (= schema [meet int? 3])])  // => [3 true]

Simplification changes constraints; canonical formatting controls their written representation. It validates the full input while preserving declared defaults, and retains opaque predicates rather than using them to discover reductions. Literal bound and default operands remain data. Scope-dependent and recursive definitions can remain intact; there is no guaranteed fully expanded form for every schema. Exhausting the normalization budget returns a resource error.