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 USD
        fact quantity = 5
        rule total = price * quantity
    "#, "example.lemma")?;

    // Evaluate the document
    let response = engine.evaluate("example", None, None)?;

    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 USD.

§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 ast::ExpressionId;
pub use ast::ExpressionIdGenerator;
pub use ast::Span;
pub use engine::Engine;
pub use error::LemmaError;
pub use inversion::Bound;
pub use inversion::BranchOutcome;
pub use inversion::Domain;
pub use inversion::Shape;
pub use inversion::ShapeBranch;
pub use inversion::Target;
pub use inversion::TargetOp;
pub use operation_result::OperationResult;
pub use parser::parse;
pub use parser::parse_facts;
pub use resource_limits::ResourceLimits;
pub use response::OperationRecord;
pub use response::Response;
pub use response::RuleResult;
pub use validator::ValidatedDocuments;
pub use validator::Validator;
pub use semantic::*;

Modules§

analysis
Reference and dependency analysis utilities
ast
AST infrastructure types
engine
error
evaluator
Pure Rust evaluation engine for Lemma
inversion
Inverse reasoning for Lemma rules
operation_result
parser
resource_limits
response
semantic
serializers
validator

Type Aliases§

LemmaResult
Result type for Lemma operations
Workspace
Temporary alias to align with the Inversion plan’s unified naming. Workspace is functionally identical to Engine and will eventually replace it.