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#"
spec example
fact price: 100
fact quantity: 5
rule total: price * quantity
"#.to_string());
engine.add_lemma_files(files).expect("failed to add files");
// Evaluate the spec (all rules, no fact values)
let now = lemma::DateTimeValue::now();
let response = engine.evaluate("example", None, &now, vec![], HashMap::new()).unwrap();§Core Concepts
§Specs
A spec is a collection of facts and rules. Specs can reference other specs 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::Context;pub use engine::Engine;pub use error::Error;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_source;pub use formatting::format_specs;pub use inversion::Bound;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::DateTimeValue;pub use parsing::ast::DepthTracker;pub use parsing::ast::LemmaFact;pub use parsing::ast::LemmaRule;pub use parsing::ast::LemmaSpec;pub use parsing::ast::MetaField;pub use parsing::ast::MetaValue;pub use parsing::ast::Span;pub use parsing::ast::TypeDef;pub use parsing::parse;pub use parsing::ParseResult;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::ExecutionPlan;pub use planning::PlanningResult;pub use planning::SpecPlanningResult;pub use planning::SpecSchema;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;
Modules§
- 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 specs
- registry
- Registry trait, types, and resolution logic for external
@...references. - serialization
- Serialization: Lemma values ↔ JSON.