I think Alexander Lamb wrote:
[Charset iso-8859-1 unsupported, filtering to ASCII...]
> Hello,
> 
> I use definstance for a "context" object in Java. However, several other
> objects will be used in the LHS of the rule but don't exist as a
> definstance. I suppose, that's ok.
> 

Yes, it is.

> Now, my understanding is that if you want to match the head of a rule with a
> java object, it needs to be a definstance. eg:

Yes, that's right.

> However, anything "inside" doesn't need to. Eg:
> 
> (Defrule rule1
>     (myObject
>         (user ?x & :(eq "Alex" (get ?x name)))


Right. ?x doesn't have to be a definstance. On the other hand, it
-could- be, and then the rule might be written differently:

(defrule rule2
   (myObject (user ?x)))
   (User (OBJECT ?x) (name "Alex"))
   =>

This fragment is equivalent to yours above. If you need the value of
more than one property of the User object, the second style becomes
more convenient. It only works, of course, if ?x is an object that has
been definstanced.

> 
> My question is: does the ":" (the function call) get evaluated each time or

In rule1 above, it is evaluated only 1) when the myObject object is first
asserted (i.e., during the call the definstance) and 2) if and when a
PropertyChangeEvent is received that indicates the value of ?x may
have changed. Note that I didn't say "the name may have changed." In
rule1, only the value of the "user" slot matters to Jess. From Jess's
perspective, "(eq "Alex" (get ?x name))" is equivalent to (+ 2
2). It's not expected to change.

Note that there is no "each time." That's the essence of the Rete
algorithm.  Jess tries to never repeat any computation on unchanged
data.

Now, in rule2, getName() is called when the User object is
definstanced, and again if a PropertyChangeEvent comes in for the User
object. Therefore, if the name might change, only rule2 behaves the
way you want.

> is the value cached (like if myObject was not a dynamic object notifying of
> changes, user would be cached and a change in user would not be known to the
> Jess engine).

Yes, as you say, it would be cached. This is the whole point of static
vs. dynamic definstances.

> In this case, if the name changes, do I need to fire a property change in
> user or does the "eq" and the "get" get evaluated all the time?
> 
> Huh, I hope this was clear enough?
> 

Yes, quite clear. Hopefull ny explanation makes sense.

> It is really getting down to:
> 
> - when should a Java object which will be used in a Jess engine be asserted
> with a definstance?

When you want to match the objects's slots on the LHS of a rule.


> - when should a Java object which will be used in a Jess engine have a
> propertyChangeSupport mechanism (considering I don't want "outdated" values
> in my Rete engine, but always the values actually in my objects?
> 

When you want Jess to know about the changes, there should be
propertyChangeSupport. 



---------------------------------------------------------
Ernest Friedman-Hill  
Distributed Systems Research        Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
Org. 8920, MS 9012                  [EMAIL PROTECTED]
PO Box 969                  http://herzberg.ca.sandia.gov
Livermore, CA 94550

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