> This rule will result in a recursion if I execute the following
> statements in sequence:
>
> Jess> (defrule _1.5a ?fact <- (e5crt ?val&~0&~1&~8) => (retract
> ?fact) (assert (e5crt 2)))
> Jess> (reset)
> Jess> (assert (e5crt 9))
> Jess> (run)
> .... recursion follows!
>
> However, if I remove the (retract ?fact) from the rule above, the
> rule can fire properly.
> What is the reason which results in the recursion? Please enlighten
> me. Thanks.
Your rule is inherently recursive, because the RHS asserts a fact that's matched on
the LHS. The difference between your two versions becomes apparent only without fact
duplication.
(1) With fact duplication (type (set-fact-duplication TRUE)) both versions behave the
same way.
(2) Without fact duplication (the default) you can't assert (e5crt 2) more than once.
You don't actually create a new fact. Thus, your rule can only fire once. Retracting
the fact, though, removes the old fact and asserts a new fact, which leads to a new
activation.
Modify your rule as follows and you'll see the reason for the recursion, or, perhaps
more correctly stated, the reason why there's no recursion when you remove (retract
?fact):
(defrule _1.5a
?fact <- (e5crt ?val&~0&~1&~8)
=>
;; Keep/remove the following line to see the differences
(retract ?fact)
(bind ?id (assert (e5crt 2)))
(printout t "Fact id = " ?id crlf))
Set fact duplication to FALSE and comment out (retract ?fact). You'll observe the
following output:
Jess> (reset)
TRUE
Jess> (assert (e5crt 9))
<Fact-1>
Jess> (run)
Fact id = <Fact-2>
Fact id = FALSE
2
Greetings, Thomas
---------------------------------------------------------------------
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]
---------------------------------------------------------------------