We seem to have found a problem with logical dependencies in Jess. We
have a fact (b) that logically depends on a fact (a). If (b) is
retracted, it is automatically reasserted as long as (a) is still true.
Initially, we assert (a) as fact 0. This causes (b) to be asserted as
fact 1. We retract fact 1, causing (b) to be reasserted as fact 2.
Finally, we retract fact 0. At this point, (b) is not in working
memory, but a rule or query with (b) on the LHS still fires.
The code and output appear below. Looking at the trace, you'll note
that when (a) is retracted, fact 1 is consequently retracted (even
though it was already retracted) and fact 2 is not retracted (even
though it depends on (a)).
Code:
(defrule r
(logical (a))
(not (b))
=>
(assert (b)))
(defmodule mod)
(defrule bad-rule
(b)
=>
(printout t "BAD!!!" crlf))
(watch all)
(assert (a))
(run)
(retract 1) ;; (retract (b))
(run)
(retract 0) ;; (retract (a))
(focus mod)
(run)
(facts *)
Output:
Jess, the Rule Engine for the Java Platform
Copyright (C) 2006 Sandia Corporation
Jess Version 7.0p1 12/21/2006
==> f-0 (MAIN::a)
==> Activation: MAIN::r : f-0,
FIRE 1 MAIN::r f-0,
==> f-1 (MAIN::b)
==> Activation: mod::bad-rule : f-1
<== f-1 (MAIN::b)
==> Activation: MAIN::r : f-0,
<== Activation: mod::bad-rule : f-1
FIRE 1 MAIN::r f-0,
==> f-2 (MAIN::b)
==> Activation: mod::bad-rule : f-2
<== f-0 (MAIN::a)
<== f-1 (MAIN::b)
<== Focus MAIN
==> Focus mod
FIRE 1 mod::bad-rule f-2
BAD!!!
<== Focus mod
==> Focus MAIN
For a total of 0 facts in all modules.
begin:vcard
fn:Aaron Novstrup
n:Novstrup;Aaron
org:Stottler Henke Associates Inc.
adr;dom:;;1107 NE 45th St;Seattle;WA;98105
email;internet:[EMAIL PROTECTED]
title:AI Software Engineer
tel;work:206.545.2941
tel;cell:805.701.9786
x-mozilla-html:FALSE
url:www.stottlerhenke.com
version:2.1
end:vcard