Hi,
 
I have a problem when I use a multiple expression, in which I call a user function in a if-then-else statement :
 
... (rule)
?my-fact <- (STUFF (value ?value))
                  (CONTROL (current-value ?cv) (maximum ?max))
=>
 (bind ?new-value (+ ?cv ?value)
 (if (>= ?new-value ?max)
  then
   (modify ?my-fact (state 4) (value ?new-value))
   (updateDB-my-fact ?my-fact-id 4 ?new-value)
  else
   (modify ?my-fact (state 2) (value ?new-value))
   (updateDB-my-fact ?my-fact-id 2 ?new-value)
 )
 
This is what I get (I don't know if I deserve it ;) :

Jess reported an error in routine Funcall.execute
        while executing (if (>= ?new-value ?max) then (modify-n ?my-fact <External-Address:[I> 4 <External-Address:[I> ?new-value)
(updateDB-my-fact ?my-fact-id 4 ?new-value) else (modify-n ?my-fact <External-Address:[I> 2 <External-Address:[I>
 ?new-value) (updateDB-my-fact ?my-fact-id 2 ?new-value))
        while executing defrule my-rule.
  Message: Error during execution.
        at java.lang.Throwable.<init>(Throwable.java:84)
        at java.lang.Exception.<init>(Exception.java:35)
        at jess.JessException.<init>(JessException.java:53)
        at jess.Funcall.execute(Funcall.java:254)
        at jess.Defrule.fire(Defrule.java:205)
        at jess.Activation.fire(Activation.java:65)
        at jess.Agenda.run(Agenda.java:126)
        at jess.Agenda.run(Agenda.java:102)
        at jess.Rete.run(Rete.java:752)
        at com.Motor.treatMyStuff(Moteur.java:340)
        at java.lang.reflect.Method.invoke(Native Method)
        at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:242)
        at sun.rmi.transport.Transport$1.run(Transport.java:155)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.rmi.transport.Transport.serviceCall(Transport.java:152)
        at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:462)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:662)
        at java.lang.Thread.run(Thread.java:498)
 
updateDB-my-fact is a Java function, which work perfectly well if I call it outside the then or else part. A workaround I found is something like :
 
...
 (if (>= ?new-value ?max)
  then
   (modify ?my-fact (state 4) (value ?new-value))
   (bind ?new-state 4)
  else
   (modify ?my-fact (state 2) (value ?new-value))
   (bind ?new-state 2)
 )
 
(updateDB-my-fact ?my-fact-id ?new-state ?new-value)
...
 
which works well.
 
Emmanuel L�charny, IKTEK
06 08 33 32 61, www.iktek.com
 

Reply via email to