Mithril Language

An ontology-based programming language

Make programs
inspectable by design.

Mithril is its own ontology-based language. Its structured Form source is distinct from JSON-LD, and the two representations can be converted in either direction under a pinned context.

Language reference · living draft

conditional.mith
(mithril/module
:name "host.conditional"
:exports ["choose" "lazy"]
:functions
[(mithril/function
:name "choose"
:params [(rdf/node :name "value" :datatype "js-value")
(rdf/node :name "fallback" :datatype "js-value")]
:returns "js-value"
:body (mithril/if
:condition (mithril/call :name "js_nullish"
:args [(mithril/local :name "value")])
:then (mithril/local :name "fallback")
:else (mithril/local :name "value")))])
Tagged forms are inert data.One source → one checked meaning
01

Explicit meaning

Programs name their ontology and vocabulary. The compiler checks admitted forms instead of evaluating arbitrary host code.

02

Portable source

Mithril Form and JSON-LD 1.1 are distinct, mutually convertible representations. Sources denoting the same graph share a canonical RDF Dataset identity.

03

Bounded execution

Typed actions cross into Kotoba and Amu through checked interfaces, with host capabilities kept explicit.

01 · The language

A source form with a visible contract.

Mithril is an ontology-based language for describing programs and their meaning. A source document identifies the vocabulary it uses; the compiler projects it into RDF, validates its declared shape, and emits a typed action artifact.

Source files.mith · .mithril

Both suffixes are accepted aliases.

Readable surfaceMithril Form

Tagged S-expressions with keyword fields, nested forms, and vectors.

Convertible representationsMithril Form ↔ JSON-LD 1.1

Distinct source formats, convertible in both directions under a pinned context.

Current contractClosed and explicit

Unknown tags, fields, or shapes are refused by their admitted profile.

02 · Source grammar

Forms are read, checked, then compiled.

The excerpt below shows the canonical reader shape and the token rules that decide source spelling. The published grammar.ebnf is the token-layer table of record. Each form tag defines its own allowed fields, argument positions, types, and vocabulary; the reader accepts one top-level form and treats it as data without running Clojure, resolving namespaces, or invoking host functions.

Reader rules

  • A source file contains exactly one tagged top-level form. An unmarked source is mithril.form/v0; (mithril/form:v1) opts in to the versioned data profile.
  • Fields are keyword/value pairs; duplicate fields are rejected.
  • Vectors preserve ordered values. Nested forms must use admitted tags.
  • Integers are exact bigints in [-2^63, 2^63-1]. Decimal and hexadecimal tokens are admitted without js/Number conversion.
  • #?/#?@ conditionals are opt-in data-profile forms. [:sum ...] is code-profile surface sugar; native Amu and public-library profiles refuse sums.
  • Positional forms such as RDF constructors are specified by their own tag contract.
  • JSON-LD is a distinct, mutually convertible representation with its own JSON-LD syntax and pinned context.
Download the EBNF reader grammar
form-source       = trivia, tagged-form, trivia ;
versioned-source = trivia, [ version-marker, trivia ], tagged-form, trivia ;
tagged-form = "(", symbol, { trivia, argument }, trivia, ")" ;
argument = keyword, trivia, value | value ;
value = string | integer | boolean | nil | vector
| conditional | sum-type | tagged-form ;
symbol = ? 1 to 128 characters, none of them trivia, "(", ")", "[",
"]", "{", "}", '"', ";", or a refused dispatch character
(@, ^, `, ~, \\, #); a numeric-looking token is an integer
token, never a symbol; nil, true and false are literals ? ;
keyword = ":", ? 1 to 127 characters under the symbol rule ? ;
integer = [ "-" | "+" ], ( "0", ( "x" | "X" ), hex-digit, { hex-digit }
| "0"
| non-zero-digit, { digit } ) ;
version-marker = "(mithril/form:v1)" ;
conditional = "#?", "(", feature-test, value, { feature-test, value }, ")"
| "#?@", "(", feature-test, value, { feature-test, value }, ")" ;
feature-test = keyword | "[", keyword, { keyword }, "]" ;
sum-type = "[", ":sum", sum-name, sum-case, { sum-case }, "]" ;

This compact excerpt is checked against the published grammar. The full EBNF carries every production, profile restriction, and named refusal; it is not a promise that every tag accepts every syntactically valid value. Type and field rules remain defined by the selected Mithril vocabulary and compiler profile. Full EBNF.

03 · Execution model

Mithril sits above Kotoba and Amu.

The execution foundation is Kotoba Lang’s typed runtime and Amu compiler/backend. Amu’s self-hosting compiler path belongs to the Kotoba/Amu toolchain; Mithril’s own compiler front end remains implemented with CLJK/CLJS host primitives.

  1. 01Read inert sourceMithril Form or JSON-LD
  2. 02Check meaningCanonical RDF and closed vocabulary admission
  3. 03Build typed actionOaK transaction and Execution IR
  4. 04Execute through KotobaOsaho semantics → Amu backend

Boundary: Amu self-hosting does not mean the Mithril compiler itself is self-hosted. Mithril’s declared .mith language kernel describes and admits its orchestration; host readers, RDF adapters, and compiler primitives remain explicit implementation components.

Explore the source

See the contracts behind the syntax.

This reference tracks the open-source implementation and will evolve with its admitted forms.