Hi,

I was strugling with the following code, until I remembered that rule
activations are only affected when you assert/retract or modify facts
that can match a rule's patterns. Anyway, I think I'd better share this
problem and get further advice.

; I have 3 deftemplates:
(deftemplate a (slot b))   ; This slot _b_ will contain a reference to a
fact _b_.
(deftemplate b (slot s))   ; I want to check if there are facts _b_ and
_c_ with the same slot _s_,
(deftemplate c (slot s))   ; where _b_ will be referred to in a fact _a_.

; Then I have a rule to get a matching of slot _s_ of both _b_ and _c_
facts, where _b_ must be referred to by an _a_ fact:
(defrule r2
    (a (b ?b))
    ?b <- (b)   ; Apparently useless
    (c (s ?b.s))   ; Using dot notation
    =>
    (printout t "abc! " ?b.s crlf) )

; Some initial facts:
(deffacts my-facts
    (b (s 1))
    (a (b (fact-id 1)))   ; This is a shortcut to have slot _b_ of fact
_a_ refer to fact _b_ in the line above.
    (c (s 1)) )

; Let's do it:
(reset)
(facts)
(modify 1 (s 2))   ; Here I modify fact _b_, changing its slot _s_ to 2.
(facts)
(run)

Now, this version works as expected: rule r2 does *not* fire. However,
if I comment the "Apparently useless" pattern binding, the rule *will
fire*, although slots _s_ of both _c_ and _b_ facts no longer have the
same value!

Does this mean that when using dotted variables a pattern binding should
always be included before they are used?

Thanks.

Henrique



--------------------------------------------------------------------
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].
--------------------------------------------------------------------

Reply via email to