(defrule r1 "comment" (dog ?x) => (assert (mammal ?x))) (defrule r2 (cat ?x) => (assert (mammal ?x))) (defrule r3 (horse ?x) => (assert (mammal ?x))) (defrule w1 (horse ?x) => (assert (weight ?x 1500))) (defrule w2 (cat ?x) => (assert (weight ?x 5))) (defrule w3 (dog ?x) => (assert (weight ?x 20))) (defrule pets (mammal ?x) (weight ?x ?y) (test (< ?y 100)) => (assert (good-pet ?x))) ; example of negation and salience ; http://herzberg.ca.sandia.gov/jess/docs/70/rules.html#not_ce (defrule bad-pets (declare (salience -1)) (mammal ?x) (not (good-pet ?x)) => (printout t "bad pet: " ?x crlf)) ; http://herzberg.ca.sandia.gov/jess/docs/70/queries.html (defquery mammals (mammal ?m)) ; http://herzberg.ca.sandia.gov/jess/docs/70/deffunctions.html#deffunctions (deffunction show-mammals () (bind ?result (run-query* mammals)) (while (?result next) (printout t (?result getString m) " is a mammal" crlf))) ; http://herzberg.ca.sandia.gov/jess/docs/70/memory.html#templates ; can also have multi-slots, types restrictions, and default values (deftemplate president (slot name) (slot number) (slot state)) (defrule presidents (president (name bush) (number ?x)) => (printout t "bush: " ?x crlf)) (defrule animals1 (mammal ?x) => (assert (animal ?x))) (defrule animals2 (amphibian ?x) => (assert (animal ?x))) (defrule amph (frog ?x) => (assert (amphibian ?x))) ;(defrule show1 ; (animal ?x) ; => ; (printout t "animal: " ?x crlf)) (deffacts f1 (horse mr-ed) (cat felix) (dog fido) (frog kermit) (president (name ford) (state michigan) (number 38)) (president (name reagan) (state california) (number 40)) (president (name carter) (state georgia) (number 39)) (president (name bush) (state texas) (number 41)) (president (name clinton) (state arkansas) (number 42)) (president (name bush) (state texas) (number 43))) ; after (reset) and (run), try (facts) ; also try (show-mammals)