Whoops!  Tis true.  I admit it.

On Tue, Aug 26, 2008 at 10:23 AM, Ernest Friedman-Hill
<[EMAIL PROTECTED]>wrote:

> On Aug 25, 2008, at 1:26 PM, Marcin Krol wrote:
>
>
> I'm new to Jess and struggling with making one example work, based on
> problem from http://en.wikipedia.org/wiki/Backward_chaining
>
>
>
> (defrule frog-color
>  (need-color ?name ?)
>  (kind ?name frog)
> ...
>
>
> This is the problem here. You've used the variable "?name" in both
> patterns. That tells Jess that the "need-color" goal and the "kind" fact
> should both contain the same value in that slot. But the need-color goal is
> generated based on the failure of this rule to match:
>
> (defrule print-Fritz-color
>  (color ?name ?val) ...
>
>
> And since "color" is the first pattern in the rule, there's no indication
> what the value of "?name" should be. So the goal need-color contains "nil"
> in that position. "nil" doesn't match "Fritz" (or whatever the user types
> in) so the "kind" and "need-color" facts don't match, and so the rule
> doesn't fire.
>
> Jason's version works because he used an anonymous variable to match the
> names, but he doesn't mention this as having been the problem. The anonymous
> variables aren't constrained to having the same value.
>
> Another way to fix the program is to embed the name information in the
> need-color goal; you can do this by matching the "kind" fact in the
> print-Fritz-color rule, since, as I said, that's the rule that forces the
> backwards chaining to happen:
>
> (defrule print-Fritz-color
>  (kind ?name ?type)
>  (color ?name ?val) =>
>  (printout t "Color of " ?name " is " ?val crlf)
> )
>
>
>
>
> ---------------------------------------------------------
>
> Ernest Friedman-Hill
> Informatics & Decision Sciences, Sandia National Laboratories
> PO Box 969, MS 9012, Livermore, CA 94550
> http://www.jessrules.com
>
>
>
>
>
>
>


--
-----------------------------------------------------------
Jason Morris
Morris Technical Solutions LLC
[EMAIL PROTECTED]
(517) 304-5883

Reply via email to