Chapter 6½: inside rules/src
Two files. lib.rs is the whole engine and every rule, in about 500 lines,
and it reads well from top to bottom:
- The vocabulary.
Kind(yes-or-no, pick, how-much, how-likely),Fact(everything that can be known about a question),Value, andSource(who teaches a fact: Jev, the LLM, or Jev again). - What a rule can say.
Test(a fact is a value, or is known), andThen: anEnd(stop with this), anEffect(go and make a call), or aNote(show this; list it). RULES. The rules themselves, as data. This is the list in chapter 6, and the one place to change what the site does.Known. What has been learned so far about one question.Network.compilebuilds the Rete network from the rules;nextanddecidesay what to do;alpha,joinandusedare what the diagram draws.
tests.rs holds the engine to its promises, including the one that matters
most: every way the Jev facts can fall ends with something to show or
something to do (every_way_the_jev_facts_can_fall_ends_or_does_something).
Try it.
cargo test -p rulesruns them, offline, in well under a second.
| File | What |
|---|---|
| lib.rs | Facts, tests, rules, RULES, Known, and the Network that compiles and runs them. |
| tests.rs | The engine's tests: each kind of question takes its path, rules share the tests they have in common, a failed test fails what follows it, and every answerable outcome is covered. |
← Previous: Chapter 6, rules/ · Up: rules · Next: Chapter 7, ask/ →