6. Making Your Own Rules 31 6. Making Your Own Rules 6.1. Introducing defrules Now that we've learned how to populate Jess's working memory, we can answer the obvious question: what is it good for? The answer is that defquery s can search it to find relationships between facts, and defrule s can take actions based on the contents of one or more facts. A Jess rule is something like an if. .. then statement in a procedural language, but it is not used in a procedural way. While if. .. then statements are executed at a specific time and in a specific order, according to how the programmer writes them, Jess rules are executed whenever their if parts (their left-hand-sides or LHS s) are satisfied, given only that the rule engine is running. This makes Jess rules less deterministic than a typical procedural program. See the chapter on the Rete algorithm for an explanation of why this architecture can be many orders of magnitude faster than an equivalent set of traditional if. .. then statements. In this chapter we're going to make a lot of use of a "person" template that looks like this:
This is the end of the preview. Sign up
access the rest of the document.