Lemma Engine
A language that means business.
Lemma Engine is the Rust crate behind the Lemma language. It lets you parse, validate, and evaluate Lemma docs from your own applications while keeping the same natural, auditable semantics that the CLI exposes.
Status
Lemma is still early-stage and not yet recommended for production use. Expect breaking changes, evolving semantics, and incomplete tooling while the project matures.
Why Lemma?
- Readable by business stakeholders – rules look like the policies people already write
- Deterministic and auditable – every evaluation returns a full trace explaining the result
- Type-aware – money, dates, percentages, units, and automatic conversions are first-class
- Composable – documents extend and reference each other without boilerplate
- Multi-platform – use the engine from Rust, power the CLI/HTTP server, or ship via WebAssembly
Quick start
Add the crate:
[]
= "0.6"
Minimal example
use Engine;
let mut engine = new;
engine.add_lemma_code?;
let response = engine.evaluate?;
for result in response.results
Overriding facts at runtime
use ;
let mut engine = new;
engine.add_lemma_code?;
let overrides = parse_facts?;
let response = engine.evaluate?;
Working with JSON
use ;
let mut engine = new;
engine.add_lemma_code?;
let json = br#"{"base_price": "150 USD", "discount": 0.2}"#;
let doc = engine.get_document.unwrap;
let facts_raw = from_json?;
let overrides = parse_facts?;
let response = engine.evaluate?;
Features
- Rich type system – money, percentages, mass, length, duration, temperature, pressure, power, energy, frequency, and data sizes
- Automatic unit conversions – convert between units inside expressions without extra code
- Document composition – extend documents, override facts, and reuse rules across modules
- Audit trail – every evaluation returns the operations that led to each result
- WebAssembly build –
npm install @benrogmans/lemma-engineto run Lemma in browsers and at the edge
Installation options
As a library
CLI tool
HTTP server
WebAssembly
Documentation
- Language guide: https://benrogmans.github.io/lemma/
- API documentation: https://docs.rs/lemma-engine
- Examples: https://github.com/benrogmans/lemma/tree/main/documentation/examples
- CLI usage: https://github.com/benrogmans/lemma/blob/main/documentation/CLI.md
- Roadmap: https://github.com/benrogmans/lemma/blob/main/documentation/roadmap.md
Use cases
- Compensation plans and employment contracts
- Pricing, shipping, and discount policies
- Tax and finance calculations
- Insurance eligibility and premium rules
- Compliance and validation logic
- SLA and service-level calculations
Contributing
Contributions are very welcome! See documentation/contributing.md and the project roadmap for ideas.
License
Apache 2.0