Typed relations & links
relation names source and target entities plus edge attributes. link validates endpoint IDs and edge fields against the relation declaration.
Forma for Ontology · shipped prelude · pre-alpha
Not every Forma program compiles to TypeScript. preludes/ontology.lisp is a shipped prelude for modeling entities, relations, seed records, links, and typed queries directly into canonical, content-addressed IR validated against payload contracts. Define a Salesforce or CRM-style domain once and hand verified IR straight to any host.
(entity Account {…}) (relation ForAccount Opportunity Account {}) (seed Account "account:acme" {…}) (link ForAccount "opp:renewal" "account:acme" {}) (query open-deals :from Opportunity :where …) │ │ read → project → check → validate ▼ Content-Addressed Domain IR (zero TypeScript codegen required)
Shipped in preludes/ontology.lisp · generated reference
00 The problem
In a typical CRM or operational app, your domain graph is split across database migrations, ORM classes, seed fixtures, and ad-hoc query strings. Nothing checks that a seed record matches its schema, that a link connects the right entity types, or that a query filters on a real field. preludes/ontology.lisp checks the whole graph together and emits portable IR instead of tying you to a single target runtime.
Live-checked CRM model
Schemas, instances, and queries checked in one file.
This CRM example is checked live against the bundled preludes/ontology.lisp prelude. entity declares Account, Contact, and Opportunity schemas. relation declares typed edges between them.
seed validates every record field against its entity schema (including defaults and required attributes). query brings the entity's fields into scope so :where and :select reject unknown columns or type mismatches. In full ontology elaboration, link also validates relation instances against the declared source and target entity types.
(entity Account
{:name String
:tier String
:arr Int})
(entity Contact
{:name String
:email String})
(entity Opportunity
{:title String
:stage String
:amount Int})
(relation WorksAt Contact Account {:role String})
(relation ForAccount Opportunity Account {})
(seed Account "account:acme"
{:name "Acme Corp"
:tier "enterprise"
:arr 120000})
(seed Contact "contact:ada"
{:name "Ada Lovelace"
:email "ada@acme.example"})
(seed Opportunity "opp:renewal"
{:title "Annual Renewal"
:stage "proposal"
:amount 120000})
(query enterprise-deals
:from Opportunity
:where (>= amount 50000)
:select [title stage amount])Pure IR & payload contracts
The IR is the deliverable.
Unlike Forma for Effect, an ontology program does not need a TypeScript backend to be useful. Every form in preludes/ontology.lisp declares its exact IR shape—EntityIR, RelationIR, RecordIR, LinkIR, QueryIR—and validates its output against domain-payload artifact contracts.
Artifacts are canonical and content-addressed, so a host application, database loader, or structural workbench can verify, diff, cache, and interpret the domain graph directly without running a code generator or embedding a Lisp evaluator at runtime.
03 Beyond entities
The ontology prelude is tested across the repository's conformance fixtures and example corpus, and includes higher-level domain vocabulary alongside schemas and queries.
relation names source and target entities plus edge attributes. link validates endpoint IDs and edge fields against the relation declaration.
query injects entity attributes into :where scope as typed bindings and computes the query's result row type from :select.
identity and permission declare roles, groups, and allow/deny policies over actions and entity schemas in the same checked IR.
process, node, and edge declare entity-triggered DAGs with compile-time checks for duplicate nodes, unknown endpoints, and dependency cycles.
04 Limits
Forma checks and projects the domain model; storing and executing it belongs to your host.
query expressions and emits QueryIR; executing queries against Postgres, SQLite, or an in-memory store is the host's job.preludes/ontology.lisp and its payload contracts are actively refined as the conformance corpus grows.query. The query form reads over one :from entity; richer relational or Datalog query execution depends on host support.05 Fit
Open the Ontology sandbox to edit a CRM model against preludes/ontology.lisp, or browse the generated prelude reference for every form and IR contract.