A Rete rules engine that knows only facts, tests on facts, priority and a
network of shared nodes. What the facts are, what they can be, and what a
rule may do is a [Domain], which the host implements.
A fact is something known. A rule is a list of tests on facts and what to do when they all hold. The network is the rules with their shared tests merged: one alpha node per distinct test, and a chain of join nodes per rule, shared where rules begin alike (Forgy, 1979).
Some facts are supplied by a source outside the network, and each is a
round trip. A rules engine would ask for them one at a time, as each rule
came to need one. [Network::next] does not: it collects every such fact
that any rule still alive is waiting on, and returns them together as
[Next::Ask], so the host sends one request with N questions. The other
facts are taught by a rule's effect ([Domain::teaches]).
Nothing here does I/O or is async. [Network::next] says what to do, and
the host does it and records what it learned in [Known]. For a host
that can answer synchronously, [Network::run] is that loop, with the
source of each fact as a [Host] callback, and it records a [Trace] of
which rule fired and what it stood on, as data a host can log.
Rules are written in code ([Rule], usually a const) or loaded as data
([load]), and loading is validated against the domain's vocabulary: an
unknown fact, a value the fact cannot have, or an effect the domain does
not allow fails at load, so a bad rule cannot be run.
27#![forbid(unsafe_code)]
29mod domain; 30mod load; 31mod network; 32mod trace; 33 34pub use domain::{Domain, Known, Rule, Test, Then}; 35pub use load::{LoadError, LoadedRule, Problem, Spec, TestSpec, ThenSpec, export, load, load_specs}; 36pub use network::{Join, Network, Next, State, Terminal}; 37pub use trace::{Event, Firing, Host, Outcome, Record, Run, Trace}; 38 39#[cfg(test)] 40mod tests;