>From the backtraces it looks like you have a source license. Have a
look near line 678 in jess/MiscFunctions.java (in the call() method of
the RunQuery class:)
// Allow backwards chaining to occur
// EJFH FIXME Is this appropriate?
// engine.run(10);
Basically, I'm not 100% sure yet that it's OK to call run() from the
RHS of a rule; this is effectively a recursive call and, although
several people have uncommented that line and are using Jess the way
you describe with no problems, I want to be absolutely sure it's OK
before I ship Jess in that configuration. You're welcome to uncomment
line 680, and you should observe your program start to work as you
expect.
I think Juraj Frivolt wrote:
>
> I tried to implement a recursive version of the factorial example from the
> manual. Here is the code:
>
> (do-backward-chaining factorial)
>
> (defquery rec-factorial
> (declare (variables ?x))
> (factorial ?x ?r)
> )
>
> (defrule do-factorial
> (need-factorial ?x&:(> ?x 1) ?)
> =>
> (bind ?res (run-query rec-factorial (- ?x 1)))
> (bind ?token (call ?res next))
> (bind ?fact (call ?token fact 1))
> (bind ?slot (fact-slot-value ?fact __d))
> (bind ?r (nth$ ?slot 2))
> (assert (factorial ?x (* ?x ?r)))
> )
>
> (defrule do-factorial1
> (need-factorial ?x&0|1 ?)
> =>
> (assert (factorial ?x 1))
> )
>
> This way I could get a factorial value by calling query
> "rec-factorial". But when I run the query it does not recurse deeper and
> throws exception (NoSuchElement - see below), obviously because somewhat
> it stops firing next rules. I think this simple example should work. Also
> calling functions from the head of backchaining rules should be.
> Please explain me why these things don't work or where I was
> mistaken.
>
> Thank you
> Frivolt Gyorgy
>
> Jess reported an error in routine call
> while executing (call ?res next)
> while executing (bind ?token (call ?res next))
> while executing defrule MAIN::do-factorial
> while executing (run).
> Message: Called method threw an exception.
> Program text: ( run ) at line 4.
> Nested exception is:
> null
> java.util.NoSuchElementException
> at java.util.AbstractList$Itr.next(AbstractList.java:423)
> at java.lang.reflect.Method.invoke(Native Method)
> at jess.Call.call(ReflectFunctions.java:398)
> at jess.FunctionHolder.call(FunctionHolder.java:37)
> at jess.Funcall.execute(Funcall.java:270)
> at jess.FuncallValue.resolveValue(FuncallValue.java:33)
> at jess.Bind.call(Funcall.java:773)
> at jess.FunctionHolder.call(FunctionHolder.java:37)
> at jess.Funcall.execute(Funcall.java:270)
> at jess.Defrule.fire(Defrule.java:224)
> at jess.Activation.fire(Activation.java:62)
> at jess.Agenda.run(Agenda.java:193)
> at jess.Agenda.run(Agenda.java:172)
> at jess.Rete.run(Rete.java:979)
> at jess.HaltEtc.call(Funcall.java:1468)
> at jess.FunctionHolder.call(FunctionHolder.java:37)
> at jess.Funcall.execute(Funcall.java:270)
> at jess.Jesp.parseAndExecuteFuncall(Jesp.java:1596)
> at jess.Jesp.parseSexp(Jesp.java:183)
> at jess.Jesp.parse(Jesp.java:62)
> at jess.Main.execute(Main.java:123)
> at jess.Main.main(Main.java:23)
>
>
>
> --------------------------------------------------------------------
> 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]
> --------------------------------------------------------------------
>
---------------------------------------------------------
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]
--------------------------------------------------------------------