Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Quick Reference

This page answers: what’s the syntax for every declaration form, with one minimal example each?

For semantics and rationale, follow the cross-links into the book chapters and the RFDs.

Substrate primitives (declaration forms)

FormSyntax (minimal)What it declaresSee
metatypepub metatype kind = { rigid, sortal, provides }A user-defined metatype with axis assignmentsch02-01
metaxispub metaxis rigidity for type { rigid, anti_rigid }A user-defined axis a metatype can take values on. Typed-domain form: pub metaxis order : Nat for type (optionally where { _ > 0 }). Cross-cutting: for [type, rel]. Valid kinds: type, rel, dec, field, individual, frame, metarel.ch02-01, ch02-06
metarelpub metarel mediates = { source: relator, target: kind, ... }A user-defined relation kindch02-01
decoratorpub decorator transitive() on rel { lowers_to: shape::Transitive }A user-defined decorator that recognized-shape lowersch02-01

Concept hierarchy

FormSyntax (minimal)See
Conceptpub kind Person <: Agentch02-02
Concept with constraintspub kind Person <: Agent where { age >= 0 }ch02-02, RFD-0018
Anonymous conceptlet _: Concept; (synthesizes __anon_<hash>_<n>)ch02-02
Group axiomdisjoint(A, B, C) / complete(A, B, C) / partition(A, B, C)ch02-02
Specializationatom: Tenant <: Person (typeset alias ). In a concept-header supertype slot, : is admitted as documented sugar for <: (pub subkind X : Ypub subkind X <: Y).ch02-02, RFD-0017
Instantiationatom: alice : Tenant (instance-of-type). : at every non-header position is the instantiation operator and never overlaps with <:.ch02-02

Relations and properties

FormSyntax (minimal)See
Relationpub rel works_at(p: Person, o: Organization)ch02-03
Relation with metarelpub rel mediates(c: Commitment, p: Person) :: Mediationch02-03
Relation with decorator@[transitive] pub rel ancestor_of(a: Person, b: Person)ch02-03
Propertypub property age(p: Person) -> Natch02-03
Cardinalitypub rel hires(o: Organization, p: Person) { cardinality: 1..* }ch02-03

Rules and reasoning

FormSyntax (minimal)See
Derive rulepub derive adult(P) :- Person(P), age(P, A), A >= 18ch02-04
Multi-head deriveMultiple pub derive same_head(...) :- ... rulesch02-04
Strict rulepub strict adult(P) :- ...ch02-04
Defeasible rule(default) — same as pub derivech02-04
Override@override(other_rule) pub derive ...ch02-04
Theorem mark@[theorem] pub derive ...ch02-04
Modalbox(P), diamond(P) operatorsRFD-0018
FOL escapeunsafe logic { ... }RFD-0018

Reflection

The compiler exposes the type lattice through one intrinsic and seven std::meta predicates. All evaluate at tier:structural. Import via use std::meta::*.

FormSyntax (minimal)What it does
meta() intrinsicmeta(c) == kindType-of subject. Sugar form c :: kind lowers to the same atom. No use required (substrate, not a std::meta predicate). Ground argument required (OE0212 if free).
is_type(X)is_type(c)Universal classification — every concept satisfies it.
metatype(X, M)metatype(c, m)Bind M to the metatype keyword as a string.
supers(X, S)supers(c, s)Direct supertypes.
ancestors(X, A)ancestors(c, a)Transitive ancestors.
fields(X, F)fields(c, f)Declared field names.
axioms(X, A)axioms(c, a)Declared axioms.
module(X, M)module(c, m)Owning module path as a string.

See ch02-06, ch03-03.

Computes

FormSyntax (minimal)When to use
Form 1 (expr)compute capital_gain(s: Sale) = s.proceeds - s.basisOne-shot calculation
Form 2 (inline)compute f(x: T) { input { ... } body { ... } out { ... } }Multi-step, tier-bounded, dynamically loadable
Form 3 (Rust)compute f(x: T) -> R { ... impl rust("crate::path::fn") }Native FFI; requires Rust rebuild

See ch02-05, RFD-0006.

Queries and mutations

FormSyntax (minimal)See
Queryquery adults() :- Person(P), age(P, A), A >= 18 => Pch02-05
Mutationmutation hire(o: Organization, p: Person) { do { works_at(p, o); } return p; }ch02-05

Singular clause names: require, do, retract, emit, return. See RFD-0007.

Tests

FormSyntax (minimal)See
Testtest t1 { ... expect { diagnostic OE0211 at //~ marker } }ch03-03
Fixturefixture { let p: Person = ...; } (test-local mini-module)ch03-03
Framepub frame F { ... } + using F in testch03-03
Proof status#[unproven] test ..., #[assumed] test ...RFD-0008
Source marker//~ <label> (anchors expect blocks)ch03-03

Patterns

FormSyntax (minimal)See
Pattern declpub pattern correlative<R, D> { ... }ch03-01
Pattern instantiationuse pattern correlative<Right, Duty> as RDch03-01
Bespoke surfacecorrelative_pair(Right, Duty)ch03-01

See RFD-0019.

Modules and packages

FormSyntaxSee
Module declarationmod foo; (file foo.ar)ch04-01
Single-symbol importuse std::math::Nat;ch04-01
Glob importuse ufo::prelude::*;ch04-01
Re-exportpub use ufo::prelude::*;ch04-01
Visibilitypub (package-public) / unmarked (module-internal)RFD-0011

Tier directives

FormSyntaxEffectSee
Module-scope#dec(tier:closure) at file topCaps every declaration in this modulech05-03
Block-scope#dec(tier:fol) in blockCaps the surrounding blockch05-03
Decl-scope#dec(tier:expressive) on declarationCaps the single declarationch05-03

See RFD-0004 and tier-selection.md.

Collections

The five type constructors and their expression-level surface. See ch02-08 and RFD-0039.

FormSyntax (minimal)What it does
Type constructorsSet[T], List[T], Map[K, V], Optional[T], Range[T]Closed-set parametric type constructors. Brackets, not angle brackets.
Optional sugarT?Optional[T]Same type; reach for T? for the common 0-or-1 case.
Method callxs.size(), xs.contains(x)Desugars to <TypeOf(xs)>::m(xs, args) at elaboration.
Indexingxs[i]Desugars to List::at(xs, i) -> Optional[T] (or Map::get). Set[T] rejects with OE2406.
Slicingxs[i..j], xs[i..], xs[..j]Desugars to List::slice(xs, Range::new(i, j)). Literal bounds checked at elaboration.
Range literali..j (half-open) / i..=j (inclusive)Constructs Range[T]. Doesn’t materialize in v1.
Membershipx in xs, x not in xsDesugars to <TypeOf(xs)>::contains(xs, x) (and negation).
Comprehension[expr for x in xs where pred]Desugars to xs.filter(<pred>).map(<expr>). Binder shadowing fires OW2403.
Constructor callsSet::of(a, b), List::of(a, b), Map::of((k, v), ...), Some(x), None()Variadic / per-arity.
Mutation idiomdo { l.parents = l.parents.append(p) }Functional rebuild-and-assign; no in-place mutators in v1.

Diagrams

FormSyntax (minimal)See
Diagram blockdiagram T { concepts { Person, Organization }; layout: sugiyama; }ch03-04

See RFD-0026.

See also