Skip to main content

lemma/
lib.rs

1//! # Lemma Engine
2//!
3//! **Rules for man and machine**
4//!
5//! Lemma is a declarative programming language for expressing rules, facts, and business logic
6//! in a way that is both human-readable and machine-executable.
7//!
8//! ## Quick Start
9//!
10//! ```rust
11//! use lemma::{Engine, LemmaResult};
12//!
13//! fn main() -> LemmaResult<()> {
14//!     let mut engine = Engine::new();
15//!
16//!     // Load Lemma code
17//!     engine.add_lemma_code(r#"
18//!         doc example
19//!         fact price = 100
20//!         fact quantity = 5
21//!         rule total = price * quantity
22//!     "#, "example.lemma")?;
23//!
24//!     // Evaluate the document (all rules, no fact overrides)
25//!     let response = engine.evaluate("example", vec![], std::collections::HashMap::new())?;
26//!
27//!     Ok(())
28//! }
29//! ```
30//!
31//! ## Core Concepts
32//!
33//! ### Documents
34//! A document is a collection of facts and rules. Documents can reference
35//! other documents to build composable logic.
36//!
37//! ### Facts
38//! Facts are named values: numbers, text, dates, booleans, or typed units
39//! like `50 kilograms` or `100`.
40//!
41//! ### Rules
42//! Rules compute values based on facts and other rules. They support
43//! conditional logic through "unless" clauses.
44//!
45//! ### Types
46//! Lemma has a rich type system including units (mass, length, time, money)
47//! with automatic conversions.
48
49pub mod computation;
50pub mod engine;
51pub mod error;
52pub mod evaluation;
53pub mod inversion;
54pub mod limits;
55pub mod parsing;
56pub mod planning;
57pub mod semantic;
58pub mod serialization;
59
60#[cfg(target_arch = "wasm32")]
61pub mod wasm;
62
63pub use engine::Engine;
64pub use error::LemmaError;
65pub use evaluation::operations::{
66    ComputationKind, OperationKind, OperationRecord, OperationResult,
67};
68pub use evaluation::proof;
69pub use evaluation::response::{Facts, Response, RuleResult};
70pub use inversion::{invert, Bound, Domain, InversionResponse, Solution, Target, TargetOp};
71pub use limits::ResourceLimits;
72pub use parsing::parse;
73pub use parsing::{DepthTracker, Source, Span};
74pub use semantic::*;
75
76/// Result type for Lemma operations
77pub type LemmaResult<T> = Result<T, LemmaError>;