-------------------------------------------
Jess, the Java Expert System Shell Copyright (C) 2001 E.J. Friedman Hill and the Sandia Corporation Jess Version 6.1b3 2/28/2003
Jess> (deftemplate foo (slot bar))
(deftemplate mine (slot me))
(do-backward-chaining foo)
(defrule get-a-foo ?fact <- (need-foo) => (printout t "need a foo" crlf) (assert (foo (bar ber))) (retract ?fact))
(defrule want-a-foo (mine (me ?name)) (foo (bar bie)) => (printout t ?name " has a " ?b crlf))
;; note here that what gets asserted in get-a-foo is not ;; what want-a-foo is looking for.
(defrule dont-want-two-foos (explicit (foo)) ?fact <- (need-foo) => (printout t "don't need two" crlf) (retract ?fact))
;; note here that I'm not specifying the value in 'bar' for either ;; foo or need-foo in this test. just that there is one and the other.
TRUE
Jess> (watch all) TRUE
Jess> (reset) ==> Focus MAIN ==> f-0 (MAIN::initial-fact) ==> Focus MAIN ==> f-0 (MAIN::initial-fact) TRUE
Jess> (assert (mine (me bob))) ==> f-1 (MAIN::mine (me bob)) ==> f-2 (MAIN::need-foo (bar bie)) ==> Activation: MAIN::get-a-foo : f-2, FALSE
Jess> (facts) f-0 (MAIN::initial-fact) f-1 (MAIN::mine (me bob)) f-2 (MAIN::need-foo (bar bie)) For a total of 3 facts.
Jess> (run) FIRE 1 MAIN::get-a-foo f-2, need a foo ==> f-3 (MAIN::foo (bar ber)) ==> Activation: MAIN::dont-want-two-foos : f-3, f-2, <== Activation: MAIN::dont-want-two-foos : f-3, f-2, <== f-2 (MAIN::need-foo (bar bie)) <== Focus MAIN 1
Jess> (facts) f-0 (MAIN::initial-fact) f-1 (MAIN::mine (me bob)) f-3 (MAIN::foo (bar ber)) For a total of 3 facts.
;; I didn't expect want-a-foo to fire, because it's the wrong ;; value in the foo fact. So far, so good.
Jess> (modify (fact-id 1) (me robert)) <=> f-1 (MAIN::mine (me robert)) ==> f-4 (MAIN::need-foo (bar bie)) <Fact-1>
Jess> (facts) f-0 (MAIN::initial-fact) f-1 (MAIN::mine (me robert)) f-3 (MAIN::foo (bar ber)) f-4 (MAIN::need-foo (bar bie)) For a total of 4 facts.
Jess> (run) 0
Jess>
;; There's a new need-foo fact. But now, I expected dont-want-two-foos ;; and/or get-a-foo to fire, but neither did.
-----------------------------------
Any ideas why this happened? I wanted the dont-want-two-foos rule to retract the need-foo fact (I used salience earlier, to make sure it fired first, but it didn't work then, either).
- Bob
-------------------------------------------------------------------- To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED] --------------------------------------------------------------------
