I think Gang Liu wrote:
> 
> hi, all
> I am using half Java and half Jess script together to address our tasks and 
> main() is writted by myself. I am wonder how jess returns control to Java.
> 
> When we call executeCommand("(run)") from main(), the program control is 
> passed to Jess. How does Jess return control to Java? 1way I know is after 
> Jess inference engine finishes check all facts ,rules and fire rules, it 
> will return control to main(). Any other ways?

run() returns only when the engine stops running. This can be when
there are no more rules to fire, or when some rule calls
(halt). Alternatively, you can use run() with a numeric argument; then
you'll get control back as soon as either that many rules have fired,
or there are no more rules to fire. So you can use this as your
program's "event loop:"

while (true) {
        engine.run(3);
        doMyOwnThing();
}

Finally, you can use runUntilHalt(), which doesn't return even if
there are no rules to fire. Typically this function is called in its
own thread; then your main routine never loses control at all.

> 
> I found a fuction (exit). When  (exit) is called, it seems to stop Java VM, 
> so main() is stopped also. what I hope is that Jess stops and return control 
> to main().

The definition for (exit) says "Exits Jess and halts Java." It just
calls System.exit(0).

The definition for (halt) says "Halts rule execution. No effect
unless called from the RHS of a rule. " This is the function you're
looking for.

> 
> BTW, In which file can I find the source code for (exit)? no Intinsics.java? 
> we have multifunctions.java ...
> 

The functions marked "Intrinsic" are defined in
jess/Funcall.java. (exit) is defined in class "HaltEtc" in that file.


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