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 – dates, percentages, units, and automatic conversions are first-class
- Composable – specs 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.8.4"
Minimal example
use Engine;
use DateTimeValue;
use HashMap;
let mut engine = new;
engine.load?;
let now = now;
let response = engine.run?;
for result in response.results
Providing values at runtime
use Engine;
use DateTimeValue;
use HashMap;
let mut engine = new;
engine.load?;
let mut values = new;
values.insert;
values.insert;
let now = now;
let response = engine.run?;
Features
- Rich type system – percentages, mass, length, duration, temperature, pressure, power, energy, frequency, and data sizes
- Automatic unit conversions – convert between units inside expressions without extra code
- Spec composition – extend specs, bind 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
Constraint-style inversion (what inputs would yield a given outcome?) is planned; it is not documented as a supported API yet.
Installation options
As a library
CLI tool
HTTP server
WebAssembly
import from '@benrogmans/lemma-engine';
const engine = await ;
Build: node build.js (from engine/packages/npm/). See packages/npm/README.md.
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
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!
License
Apache 2.0