JESS: Setting fact slot value in JessListener

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

JESS: Setting fact slot value in JessListener

Dwight Hare

In my JessListener I want to set a slot value on the fact that I get on a Fact Event. I tried Rete.modify to modify the fact but got an exception that the fact was not in active memory. So figuring that the fact had not yet been added to the system I tried calling setSlotValue on the fact but then got a very strange behavior where my JessListener is called again with the same fact, without the slot value I set, and with the factid incremented. If my code again does a setSlotValue on this fact then my JessListener gets called again with the same fact, without the slot I set, and with the factid incremented, and this becomes an infinite loop. If I set a boolean and ignore the second call, then I end up with two facts, one with the slot having value nil and the other with the value I set.

 

I am assuming by this behavior that I am not supposed to modify the fact I get in my JessListener. Is there any way to set the slot value for this fact?

 

Dwight

 

Reply | Threaded
Open this post in threaded view
|

JESS: RE: Setting fact slot value in JessListener

Friedman-Hill, Ernest
Sounds like your change listener might be better implemented as a rule with a "no-loop" declaration. Your rule would be invoked when the fact it matches changes, and it would be invoked at an appropriate time to modify the fact.

In my JessListener I want to set a slot value on the fact that I get on a Fact Event. I tried Rete.modify to modify the fact but got an exception that the fact was not in active memory. So figuring that the fact had not yet been added to the system I tried calling setSlotValue on the fact but then got a very strange behavior where my JessListener is called again with the same fact, without the slot value I set, and with the factid incremented. If my code again does a setSlotValue on this fact then my JessListener gets called again with the same fact, without the slot I set, and with the factid incremented, and this becomes an infinite loop. If I set a boolean and ignore the second call, then I end up with two facts, one with the slot having value nil and the other with the value I set.

 

I am assuming by this behavior that I am not supposed to modify the fact I get in my JessListener. Is there any way to set the slot value for this fact?

 

Dwight