I think Robert Gaimari wrote:
> I'm having an odd problem. Here is a run to show what's happening.
"Odd" only in the sense that Jess's backward chaining is a bit odd,
but this is just how it works. Read on for an explanation.
>
> (defrule get-a-foo
> ?fact <- (need-foo)
> =>
> (printout t "need a foo" crlf)
> (assert (foo (bar ber)))
> (retract ?fact))
>
...
>
> (defrule dont-want-two-foos
> (explicit (foo))
> ?fact <- (need-foo)
> =>
> (printout t "don't need two" crlf)
> (retract ?fact))
...
>
> 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.
>
> ;; 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.
>
If you use ppdefrule to look at get-a-foo and dont-want-two-foos,
you'll see that Jess adds a pattern to the end of the LHS of each rule
with a need-foo pattern. It's a negated pattern and otherwise it
matches the need-foo pattern -- i.e., if you have a plain old
(need-foo), then you'll get a (not (foo)) automatically.
Jess> (ppdefrule get-a-foo)
"(defrule MAIN::get-a-foo
?fact <- (MAIN::need-foo)
(not (MAIN::foo))
=> ...
Jess> (ppdefrule dont-want-two-foos)
"(defrule MAIN::dont-want-two-foos
(explicit (MAIN::foo))
?fact <- (MAIN::need-foo)
(not (MAIN::foo))
=> ...
Jess does this to prevent endless loops. Basically, a need-foo rule
has to advertise the kind of foo it's going to produce, or Jess will
not know that firing the rule would do any good. So, for instance,
although get-a-foo will still be incorrect in some sense, it would
fire when you expected it to if you changed it to
> (defrule get-a-foo
> ?fact <- (need-foo (bar ?x))
> =>
Because then it will get compiled to
(defrule get-a-foo
?fact <- (need-foo (bar ?x))
(not (foo (bar ?x)))
=>
i.e., we need a fact that currently doesn't exist. Of course, for this
to be a "correct" rule, it should assert precisely the fact that it
advertises it will -- i.e., (foo (bar ?x)).
---------------------------------------------------------
Ernest Friedman-Hill
Distributed Systems Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
PO Box 969, MS 9012 [EMAIL PROTECTED]
Livermore, CA 94550 http://herzberg.ca.sandia.gov
--------------------------------------------------------------------
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]
--------------------------------------------------------------------