I have analyzed this some, but the mail just went to Henrique.
-W

---------- Forwarded message ----------
From: Wolfgang Laun <[email protected]>
Date: 21 July 2010 08:20
Subject: Re: JESS: Nested not conditional element with slots referring to facts
To: Henrique Lopes Cardoso <[email protected]>


Hmm, I was sure that I did have a problem with references within a
deffacts at one time. However, a little experimenting shown that

(defrule r
 (not (and ?x <- (a ?) (not (b ?x)) ) )
 =>... )

is (according  to (ppdefrul r)) internally represented as

(defrule MAIN::r
  (initial-fact)
  (not ?x <- (and ?x <- (a ?_021__blank_17) (not (b ?_0022_x))))
  => ... )

Besides the (incorrect) duplication of ?x in front of (and), the identity of
the bound variable ?x is lost. I *guess* that some sort of (usually) optimizing
transformation is being done which results in

(defrule rx
  (or (not (a ?))  (b ?x))
=> ... )

which is always true due to any (b) being present.

If rule rx is added, it behaves just like rule r, i.e., when there is
no fact (a) but
some fact (x) to provide the fact-id 1,  both r and rx fire.
Conversely, removing
fact (b (slot-id 1)) with just a single (a 1) results in both rules
(r) and (rx) not
firing.

I'd say this is a bug: the aforementioned transformation may not be done
if there are *fact* bindings to achieve linkage between the patterns.

BTW, if the example from the Jess manual is modfied with a redundant
variable binding:for the x-fact:

 (defrule xy (not (and ?xf <- (x ?v) (not (y ?v)))) => ... )

(ppdefrule xy) also produces a syntactically incorrect rule, while the
variable bindings for slot values are retained correctly, just renamed
to make them local within the outer (not), .

 (defrule MAIN::xy
  (initial-fact)
  (not ?xf <- (and ?xf <- (x ?_021_v) (not (y ?_021_v))))  => ... )

Best
Wolfgang


On 20 July 2010 22:04, Henrique Lopes Cardoso <[email protected]> wrote:
> Actually, asserts do work, because (deffacts) are added to working memory by
> a call to (reset). This is wy I am calling (facts) before (run), to make
> sure facts are in working memory as intended.
>
> Anyway, I tried (assert)ing them one by one and it still does not work as
> expected.
>
> It must be something else.
>
> Henrique
>
>
> Citando Wolfgang Laun <[email protected]>:
>
>> When (deffacts) is evaluated to build the facts, (fact-id) won't
>> return a fact since only the (reset) inserts
>> the defined facts. You'll have to use dynamic insertion with (assert)
>> to insert a fact referring to another
>> fact.
>>
>> -W
>>
>> On 20 July 2010 19:23, Henrique Lopes Cardoso <[email protected]> wrote:
>>>
>>> Hi,
>>>
>>> I have just reproduced the example of section 6.10 of the Jess manual:
>>>
>>>    (defrule forall-example
>>>        (not (and (a ?x)
>>>                  (not (b ?x)) ) )
>>>        =>
>>>        (printout t "whassup?" crlf) )
>>>
>>>    (deffacts qwe
>>>        (a 1)
>>>    ;    (a 2)
>>>        (b 1) )
>>>
>>>    (reset) (facts) (run)
>>>
>>> So in this case, if I comment out fact (a 2), the rule stops firing.
>>> But then I tried to implement the following rule:
>>>
>>>    (defrule r
>>>        (not (and ?x <- (a ?)   ; variable binding
>>>                  (not (b ?x)) ) )   ; check if there is a b referring
>>> to the a fact
>>>        =>
>>>        (printout t "sure thing!" crlf) )
>>>
>>>    (deffacts qwe
>>>        (a 1)
>>>    ;    (a 2)
>>>        (b (fact-id 1)) )   ; fact b referring to fact (a 1)
>>>
>>>    (reset) (facts) (run)
>>>
>>> It's quite similar to the previous one, but now I am inspecting if fact
>>> b contains a reference to fact a.
>>> In this case the rule does not cease to fire when I comment out (a 2).
>>>
>>> Am I missing something?
>>>
>>> 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].
>>> --------------------------------------------------------------------
>>>
>>>
>>
>>
>>
>>
>> --------------------------------------------------------------------
>> 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].
>> --------------------------------------------------------------------
>>
>>
>
>
>




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