Jess Information

Jess Home
Jess 7 Features
Download Now!
Online Demo

Mailing List
Jess Wiki

More information Related Web Sites
User Contributions
JSR94 Info
Developer's Log
About This Site

JESS ®, the Rule Engine for the JavaTM Platform

Jess Wiki: Multi Rule Program


To demonstrate one rule triggering another, and using both explicit and implicit deftemplates when using facts (asserts).


Create 2 rules. One which is triggered on initialisation, looks for a car that is newer than 1991. It makes an assertion (newcar) which is picked up by the next rule which prints out 'that new car smell'


  • (reset). Clears working memory. Not necessary, but docs seem to indicate it is good practice.

  • (deftemplate). Define a car type. It's only slot is year.

  • (defrule). This is triggered if a car is found with a year after 1991. If it finds one it asserts newcar. This is a fact that doesn't have an associated template. It has an implicit deftemplate.

  • (defrule). This is triggered when it finds a newcar fact. It merely prints out that new car smell

  • (deffunction) init. I like to initialise data in a single specified place, which I do here. I assert that there are 2 cars with different years. One of these will trigger rule_1. Can you guess which one?

  • (init). Call my initialisation function.


;define the template (equiv. of class) 
(deftemplate car (slot year (type INTEGER)))

;define a rule to find fast cars
(defrule rule_1
    (car {year > 1991})
    (printout t "there is a new car" crlf)
    (assert (newcar))

;define a rule to find fords
(defrule rule_2
    (printout t "that new car smell!!!" crlf)

;initialise the data
(deffunction init ()
    (assert (car (year 1992)))
    (assert (car (year 1990)))


;should always be called
there is a new car
that new car smell!!!

Front Page | Sandbox | Recent Changes | Powered by Friki | Last Edited: 09 November 2008