Skip to main content

Crate lemma

Crate lemma 

Source
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, SourceType};
use std::collections::HashMap;

let mut engine = Engine::new();

// Load Lemma code
engine.load(r#"
    spec example
    fact price: 100
    fact quantity: 5
    rule total: price * quantity
"#, SourceType::Labeled("example.lemma")).expect("failed to load");

// Evaluate the spec (all rules, no fact values)
let now = lemma::DateTimeValue::now();
let response = engine.run("example", Some(&now), HashMap::new(), false).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 engine::Errors;
pub use engine::SourceType;
pub use error::Error;
pub use error::RequestErrorKind;
pub use evaluation::explanation;
pub use evaluation::operations::ComputationKind;
pub use evaluation::operations::OperationKind;
pub use evaluation::operations::OperationRecord;
pub use evaluation::operations::OperationResult;
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::is_same_spec;
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::TypeDefiningSpec;
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;
pub use spec_id::parse_spec_id;

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.
spec_id
Parse spec identifier (name or name~hash) with request-level error handling. Not Lemma source validation — invalid spec id is an API/request error.