JESS: Userfunction on LHS called only once

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

JESS: Userfunction on LHS called only once

Manuel Ziegler
Hello everybody,

my scenario is as follows:

I have a rule like

(defrule i-rule
 (test (> (dynamic-userfunction) 3))
 =>
 (do-something-else)
)

My problem is as follows:

The dynamic-userfunction is just called when the .clp file
is loaded by the (batch)-command in Java. If I got that
rigth, then this is due to the Rete algorithm, which looks
for one time which return value this function has and then
saves this -- if I got that right.

But what if this dynamic-userfunction returns different values
over time? (What is in most cases when reading some values
out of Java, isn't it?) Is it possible to let the userfunction be
called each time the engine is run?

Greetings and thanks in advance.

-manuel ziegler

--------------------------------------------------------------------
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: Userfunction on LHS called only once

friedman_hill ernest j
I think Manuel Ziegler wrote:

>
> (defrule i-rule
>  (test (> (dynamic-userfunction) 3))
>  =>
>  (do-something-else)
> )
>
> My problem is as follows:
>
> The dynamic-userfunction is just called when the .clp file
> is loaded by the (batch)-command in Java.

Pattern-matching is driven by fact assertion, retraction, and
modification. The manual does explain that a "test" CE will be
evaluated when the preceding pattern is matched, and if there is no
preceding pattern, then the "(initial-fact)" fact created by a call to
(reset) will be used.

If you want to react to a time-varying function, then you need a way
to notify Jess when that value changes. Jess makes it easy to use a
JavaBean which support PropertyChangeEvents to do this. If you don't
want to use Java code, then one alternative is simply to assert a fact
containing the function's return value in a slot, and then explicitly
modify that fact whenever the return value would change.

The important thing you must realize is that Jess can't react to a
change unless it knows about the change. Jess won't poll a function,
calling it over and over again, waiting for the value to change --
that would be very inefficient, right?

Of course, if you *want* Jess to poll your function, then look at the
"idle-rule" question in the FAQ
(http://herzberg.ca.sandia.gov/jess/FAQ.shtml) which should give you
an idea of how to do it.





---------------------------------------------------------
Ernest Friedman-Hill  
Advanced Software Research          Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
PO Box 969, MS 9012                 [hidden email]
Livermore, CA 94550         http://herzberg.ca.sandia.gov

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