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, LemmaResult};

fn main() -> LemmaResult<()> {
    let mut engine = Engine::new();

    // Load Lemma code
    engine.add_lemma_code(r#"
        doc example
        fact price = 100
        fact quantity = 5
        rule total = price * quantity
    "#, "example.lemma")?;

    // Evaluate the document (all rules, no fact overrides)
    let response = engine.evaluate("example", vec![], std::collections::HashMap::new())?;

    Ok(())
}

§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 inversion::invert;
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::parse;
pub use parsing::DepthTracker;
pub use parsing::Source;
pub use parsing::Span;
pub use semantic::*;

Modules§

computation
engine
error
evaluation
Pure Rust evaluation engine for Lemma
inversion
World-based inverse reasoning for Lemma rules
limits
parsing
planning
Planning module for Lemma documents
semantic
serialization
Serialization module for converting external data formats to string values.

Type Aliases§

LemmaResult
Result type for Lemma operations