- An interpreter for a rule language borrowed from CLIPS.
- CLIPS is basically a small version of LISP, making Jess a LISP interpreter written in Java.
- Supports Atoms, Numbers, Strings.
- Comments are started with a ";" - ; This is a list (a b c)
Lists
- Lists are fundamental structure in LISP ...
(+ 3 2) (a b c)
Functions
- Functions are core to computing. Many supported as part of JESS while many more are extensions other people have contributed.
- Core Intrinsic Functions - +, -, read, while, ...
- User supported - MATH, STRING, ....
Variables
- Programming variables are atoms that begin with the question mark (?) character.
- A variable whose first character is instead a "$" (for example, $?X) is a multivariable.
- You assign to any variable using the bind function:
(bind ?x "The value")
(bind $?grocery-list (create$ eggs bread milk))
Deffunctions
- Construct to define functions that you can then call from JESS.
(deffunction max (?a ?b)
(if (> ?a ?b) then
(return ?a)
else
(return ?b)))
Facts
- Ordered facts - list whose head is an atom.
(temperature 98.6)
- Unordered facts - structured 'slots' which must be accessed by name.
(deftemplate automobile
"A specific car."
(slot make)
(slot model)
(slot year)
(slot color (default white)))
Defclasses
- Construct to tell Jess to be able to use a specific Java class like a deftemplate.
(defclass pump jess.examples.pumps.Pump)
IF
public class Pump
{
public String getName() { ... }
public int getFlow() { ... }
public void setFlow(int f) { ... }
}
THEN RESULT IS ...
(deftemplate pump "$JAVA-OBJECT$ jess.examples.pumps.Pump"
(slot class)
(slot name)
(slot flow)
(slot OBJECT))
Deffacts
- Construct to define a list of facts that should be made true when the JESS system is started or reset
(deffacts automobiles
(automobile (make Chrysler) (model Le Baron) (year 1997))
(automobile (make Ford) (model Contour) (year 1996))
(automobile (make Nash) (model Rambler) (year 1948)))
Defrules
- Construct to define a rule to JESS.
- The main purpose of a shell like JESS is to support the execution of rules.
- Somewhat like the IF...THEN statements of other programming languages.
- JESS constantly tests to see if any of the IFs become true, and executes the corresponding THENs
- The 'intelligence' is encoded in the rules.
(defrule example-1
"Announce 'a b c' facts"
(a b c)
=>
(printout t "Saw 'a b c'!" crlf))
- You can try this in the interpreter.
Jess> (clear)
TRUE
Jess> (watch all)
TRUE
Jess> (defrule example-1
"Announce 'a b c' facts"
(a b c)
=>
(printout t "Saw 'a b c'!" crlf))
example-1: +1+1+1+1+t
TRUE
Jess> (assert (a b c))
==> Activation: example-1 : f-0
==> (a b c)
<Fact-0>
Jess> (run)
FIRE [Defrule: example-1 "Announce 'a b c' facts";
- patterns; salience: 0] f-0
Saw 'a b c'!
TRUE
Jess>
(defrule example-5
?fact <- (command "retract me")
=>
(retract ?fact))
- Salience can be placed in rules to help control firing order.
(declare (salience -100))
[ReteExample | JessAndAgents | JessAndJava]
(last edited September 30, 2009)
Find Page by browsing or searching