JESS: Explicit pattern bindings when using dotted notation in slots with fact reference

classic Classic list List threaded Threaded
4 messages Options
hlc
Reply | Threaded
Open this post in threaded view
|

JESS: Explicit pattern bindings when using dotted notation in slots with fact reference

hlc
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 [hidden email]'
in the BODY of a message to [hidden email], NOT to the list
(use your own address!) List problems? Notify [hidden email].
--------------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: JESS: Explicit pattern bindings when using dotted notation in slots with fact reference

Friedman-Hill, Ernest

On Jun 29, 2010, at 6:42 AM, Henrique Lopes Cardoso wrote:

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

This isn't really limited to dotted variables; you'd see the same  
issue if you wrote the code using fact-slot-value, or reflection. For  
a match to be made or unmade, the particular Rete node that performs  
the test needs to be notified that the relevant fact(s) have changed.  
That won't happen unless those relevant facts are explicitly matched  
by patterns. If the facts are dynamic -- i.e., if the slot values will  
change at runtime -- then I'd prefer to write this rule as

(defrule r2
    (a (b ?b))
    ?b <- (b (s ?s))
    (c (s ?s))
    =>



---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences, Sandia National Laboratories
PO Box 969, MS 9012, Livermore, CA 94550
http://www.jessrules.com







--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [hidden email]'
in the BODY of a message to [hidden email], NOT to the list
(use your own address!) List problems? Notify [hidden email].
--------------------------------------------------------------------

hlc
Reply | Threaded
Open this post in threaded view
|

Re: JESS: Explicit pattern bindings when using dotted notation in slots with fact reference

hlc
Thanks for the clarification.

By the way, in section 3.7.1 of the Jess manual: "You can use dotted
variables in any procedural code, but they won't generally work in the
pattern matching parts of a rule."
Does this mean that the use of dot notation is discouraged in the LHS of
rules? Section 6.2.1 seems to provide an example where it is used in the
LHS, although with a Java pattern.

Henrique


Ernest Friedman-Hill wrote:

>
> On Jun 29, 2010, at 6:42 AM, Henrique Lopes Cardoso wrote:
>
>>
>> Does this mean that when using dotted variables a pattern binding should
>> always be included before they are used?
>>
>
> This isn't really limited to dotted variables; you'd see the same
> issue if you wrote the code using fact-slot-value, or reflection. For
> a match to be made or unmade, the particular Rete node that performs
> the test needs to be notified that the relevant fact(s) have changed.
> That won't happen unless those relevant facts are explicitly matched
> by patterns. If the facts are dynamic -- i.e., if the slot values will
> change at runtime -- then I'd prefer to write this rule as
>
> (defrule r2
>    (a (b ?b))
>    ?b <- (b (s ?s))
>    (c (s ?s))
>    =>
>
>
>
> ---------------------------------------------------------
> Ernest Friedman-Hill
> Informatics & Decision Sciences, Sandia National Laboratories
> PO Box 969, MS 9012, Livermore, CA 94550
> http://www.jessrules.com



--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [hidden email]'
in the BODY of a message to [hidden email], NOT to the list
(use your own address!) List problems? Notify [hidden email].
--------------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: JESS: Explicit pattern bindings when using dotted notation in slots with fact reference

Friedman-Hill, Ernest
I think that text is referring to dotted variables used to access  
properties of Java objects, as opposed to slot values of facts.


On Jun 29, 2010, at 10:09 AM, Henrique Lopes Cardoso wrote:

> Thanks for the clarification.
>
> By the way, in section 3.7.1 of the Jess manual: "You can use dotted
> variables in any procedural code, but they won't generally work in the
> pattern matching parts of a rule."
> Does this mean that the use of dot notation is discouraged in the  
> LHS of
> rules? Section 6.2.1 seems to provide an example where it is used in  
> the
> LHS, although with a Java pattern.
>
> Henrique
>
>
> Ernest Friedman-Hill wrote:
>>
>> On Jun 29, 2010, at 6:42 AM, Henrique Lopes Cardoso wrote:
>>
>>>
>>> Does this mean that when using dotted variables a pattern binding  
>>> should
>>> always be included before they are used?
>>>
>>
>> This isn't really limited to dotted variables; you'd see the same
>> issue if you wrote the code using fact-slot-value, or reflection. For
>> a match to be made or unmade, the particular Rete node that performs
>> the test needs to be notified that the relevant fact(s) have changed.
>> That won't happen unless those relevant facts are explicitly matched
>> by patterns. If the facts are dynamic -- i.e., if the slot values  
>> will
>> change at runtime -- then I'd prefer to write this rule as
>>
>> (defrule r2
>>   (a (b ?b))
>>   ?b <- (b (s ?s))
>>   (c (s ?s))
>>   =>
>>
>>
>>
>> ---------------------------------------------------------
>> Ernest Friedman-Hill
>> Informatics & Decision Sciences, Sandia National Laboratories
>> PO Box 969, MS 9012, Livermore, CA 94550
>> http://www.jessrules.com
>
>
>
> --------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe jess-users  
> [hidden email]'
> in the BODY of a message to [hidden email], NOT to the list
> (use your own address!) List problems? Notify [hidden email]
> .
> --------------------------------------------------------------------

---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences          Phone: (925) 294-2154
Sandia National Labs
PO Box 969, MS 9012                            [hidden email]
Livermore, CA 94550                             http://www.jessrules.com





--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [hidden email]'
in the BODY of a message to [hidden email], NOT to the list
(use your own address!) List problems? Notify [hidden email].
--------------------------------------------------------------------