On Dec 9, 2006, at 2:53 PM, J Michael Dean wrote:

The GlucoseDecision.setAdviceText() is a trivial setter.

OK, that's all we need to know. The GlucoseDecision class supports PropertyChangeListeners, and Jess takes that as a promise that whenever setX() is called, an "X has changed" event will come back. Until that event has come, Jess's working memory image of that object is unchanged. Since your setter breaks the contract and doesn't send the event, Jess loses track of the values of your object's slots.

So here's the scenario. Imagine that the "adviceText" slot contains something, we'll call it "?X". You call the equivalent of

(modify ?decision (str-cat ?X "more advice"))

Jess then calls setAdviceText(?X + "more advice"), and then that's what the object contains. But working memory isn't updated until the change event comes back -- and in this case, it never does. Now working memory and the object are out of sync, and this is bad.

Then the next rule fires and it calls

(modify ?decision (str-cat ?X "even more advice"))

and so Jess calls setAdviceText(?X + "even more advice"). The value of ?X is the same since working memory was never updated. The text "more advice" is completely lost! That's what's happening here.

So there are two different ways to fix this. First, you can explicitly tell Jess to ignore your PropertyChange mechanism, since it's broken. To do this, you could say '(definstance GlucoseDecision ? decision static)' instead of '(add ?decision)'. For "static" definstances -- those that don't have PropertyChangeListeners -- the 'modify' function changes both working memory and the Java object.

The other way would be to fix setAdviceText so that it sends an appropriate event after setting the property value.

---------------------------------------------------------
Ernest Friedman-Hill
Advanced Software Research          Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
PO Box 969, MS 9012                 [EMAIL PROTECTED]
Livermore, CA 94550                 http://www.jessrules.com
--------------------------------------------------------------------
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