Expand description
§Lemma Engine
Rules for man and machine
Lemma is a declarative programming language for expressing rules, facts, and business logic in a way that is both human-readable and machine-executable.
§Quick Start
use lemma::Engine;
use std::collections::HashMap;
let mut engine = Engine::new();
// Load Lemma code
let mut files = HashMap::new();
files.insert("example.lemma".to_string(), r#"
doc example
fact price = 100
fact quantity = 5
rule total = price * quantity
"#.to_string());
tokio::runtime::Runtime::new().unwrap()
.block_on(engine.add_lemma_files(files))
.expect("failed to add files");
// Evaluate the document (all rules, no fact values)
let response = engine.evaluate("example", vec![], HashMap::new()).unwrap();§Core Concepts
§Documents
A document is a collection of facts and rules. Documents can reference other documents to build composable logic.
§Facts
Facts are named values: numbers, text, dates, booleans, or typed units
like 50 kilograms or 100.
§Rules
Rules compute values based on facts and other rules. They support conditional logic through “unless” clauses.
§Types
Lemma has a rich type system including units (mass, length, time, money) with automatic conversions.
Re-exports§
pub use engine::Engine;pub use error::LemmaError;pub use evaluation::operations::ComputationKind;pub use evaluation::operations::OperationKind;pub use evaluation::operations::OperationRecord;pub use evaluation::operations::OperationResult;pub use evaluation::proof;pub use evaluation::response::Facts;pub use evaluation::response::Response;pub use evaluation::response::RuleResult;pub use formatting::format_docs;pub use formatting::format_source;pub use inversion::invert;pub use inversion::Bound;pub use inversion::DerivedExpression;pub use inversion::Domain;pub use inversion::InversionResponse;pub use inversion::Solution;pub use inversion::Target;pub use inversion::TargetOp;pub use limits::ResourceLimits;pub use parsing::ast::DepthTracker;pub use parsing::ast::Span;pub use parsing::parse;pub use parsing::Source;pub use planning::semantics::FactPath;pub use planning::semantics::LemmaType;pub use planning::semantics::LiteralValue;pub use planning::semantics::RatioUnit;pub use planning::semantics::RatioUnits;pub use planning::semantics::RulePath;pub use planning::semantics::ScaleUnit;pub use planning::semantics::ScaleUnits;pub use planning::semantics::SemanticDurationUnit;pub use planning::semantics::TypeSpecification;pub use planning::semantics::ValueKind;pub use planning::DocumentSchema;pub use planning::ExecutionPlan;pub use registry::LemmaBase;pub use registry::resolve_registry_references;pub use registry::Registry;pub use registry::RegistryBundle;pub use registry::RegistryError;pub use registry::RegistryErrorKind;pub use parsing::ast::*;
Modules§
- computation
- engine
- error
- evaluation
- Pure Rust evaluation engine for Lemma
- formatting
- Lemma source code formatting.
- inversion
- World-based inverse reasoning for Lemma rules
- limits
- parsing
- planning
- Planning module for Lemma documents
- registry
- Registry trait, types, and resolution logic for external
@...references. - serialization
- Serialization module for converting external data formats to string values.
Type Aliases§
- Lemma
Result - Result type for Lemma operations