Getting started
Lemma is a pure, declarative language for business rules that stakeholders can read and systems can evaluate precisely. Rules live in Specs: named collections of Data (inputs) and Rules (computed outputs). Lemma validates every Spec before evaluation; after that, each Rule returns a value or a Veto (no value). Explanations are opt-in (lemma run -x / explain: true).
This chapter walks through installation, your first Spec, and running it from the CLI.
Install
Install the CLI from crates.io/crates/lemma:
cargo install lemma
Or via npm:
npm install -g lemma
For library bindings, WASM, editor support, and Docker, see Installation. To embed Lemma in your application, see Tools & SDKs.
Your first Spec
Create shipping.lemma:
spec shipping
data money: measure
-> unit eur 1.00
-> unit usd 0.91
-> decimals 2
-> minimum 0 eur
data weight: measure
-> unit kilogram 1
-> unit gram 0.001
data is_express: true
data package_weight: 2.5 kilogram
rule express_fee: 0 eur
unless is_express then 4.99 eur
rule base_shipping: 5.99 eur
unless package_weight > 1 kilogram then 8.99 eur
unless package_weight > 5 kilogram then 15.99 eur
rule total_cost: base_shipping + express_fee
Three building blocks appear here:
specnames the Rule set.datadefines inputs with types and constraints (-> unit,-> decimals,-> minimum).rulecomputes values;unlessclauses add conditional logic (the last matching condition wins).
There is no inline comment syntax. The only in-source documentation is a commentary block: triple-quoted """...""" placed immediately after the Spec line. The syntax relies on keywords instead of colons or brackets. Indentation is for readability only; newlines are optional. Apply the standard format with:
lemma format
Run it
lemma run shipping
Output:
┌───────────────┬───────────┐
│ base_shipping ┆ 8.99 eur │
├───────────────┼───────────┤
│ express_fee ┆ 4.99 eur │
├───────────────┼───────────┤
│ total_cost ┆ 13.98 eur │
└───────────────┴───────────┘
Override Data from the command line:
lemma run shipping is_express=false package_weight="6.0 kilogram"
Output:
┌───────────────┬───────────┐
│ base_shipping ┆ 15.99 eur │
├───────────────┼───────────┤
│ express_fee ┆ 0.00 eur │
├───────────────┼───────────┤
│ total_cost ┆ 15.99 eur │
└───────────────┴───────────┘
Other useful flags:
lemma run shipping --json
Machine-readable output.
lemma run shipping -x
Show how each Rule was evaluated (human reasoning table; with --json, per-rule explanation objects per explanation.v1.json).
lemma show shipping
Show the static interface (data types, constraints, and rules reachable after normalize). Overlay-aware needs for a concrete run come from each rule's missing_data; static types and suggestions are on lemma show only.
See CLI reference for all commands and flags.
Next up
Specs, Data, and Rules: how Specs are structured, open inputs, constraints, and Rule references.