I think chris poppe wrote:
> 
> Hello I'm facing the following problem, I'm trying to insert an object into
> jess, firing a rule on it wich then returns this object.

 [ Rule deleted -- see below] 

> but something goes wrong :the rule is fired twice with only one object?
> 
> I know it has something to do with the (OBJECT ?cart) but I couldnt think of
> a  different way to send the object from jess to the java code.

There's nothing at all wrong with what you're doing with the "OBJECT"
slot. That's a perfectly fine way to accomplish your goal.

>      rete.executeCommand("(reset)");
>     rete.reset();

Note that these two lines do exactly the same thing. The second form
is preferred.

> 
> Funcall f = new Funcall("definstance", rete);
>         f=new Funcall("definstance", rete);
>         f.add(new Value("card", RU.ATOM));
>         f.add(new Value(sh));
>         f.execute(rete.getGlobalContext());

There's a rete.definstance() method that is more convenient to use!

Anyway, based just on what you've shown us, there's no reason why the
rule should fire twice. Since it's a dynamic definstance, however,
modifying any of the slots will update the fact which may well cause
the rule to fire again. Maybe something in the batch file you haven't
shown us is doing this?

I wanted to make one comment about this rule, since this is a common
mistake: 

> (defrule petstore
>   ( card (name ?name)(item1 ?item1) (message ?message) (item2 ?item2)
> (count1 ?count1) (count2 ?count2) (OBJECT ?cart) )
>   (test (> ?count1 2))

In general, use the "test" conditional element only to improve
readability, or in those few cases where there's no other way to do
something. It would be more efficient to write

(defrule petstore
   (card (name ?name)
         (item1 ?item1)
         (message ?message)
         (item2 ?item2)
         (count1 ?count1&:(> ?count1 2))
         (count2 ?count2)
         (OBJECT ?cart))

If you use a few "test" CEs here and there, it doesn't matter. But if
you use it for every single test, as some beginners decide to for
reasons that escape me, then you're telling Jess to use noticeably
more memory for no purpose whatsoever.




---------------------------------------------------------
Ernest Friedman-Hill  
Science and Engineering PSEs        Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
PO Box 969, MS 9012                 [EMAIL PROTECTED]
Livermore, CA 94550         http://herzberg.ca.sandia.gov

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