That's what the "OBJECT" slot is for - it holds the object.

(defrule write-a
  (a (num ?n) (OBJECT ?o))
  =>        
  (call ?o setNum (+ ?n 1)))

Note that in this case, you can use "modify" if you want, since what
you're doing is modifying one of the matched slots. That would look
like this, and have the identical effect:

(defrule write-a-2
  ?f <- (a (num ?n))
  =>
  (modify ?f (num (+ ?n 1))))

The advantage here is that (a) could be either a regular fact or a
definstance, and the code still works; useful if you ever want to
change this.

I think Jerome Poirier wrote:
> Hello,
> 
> First I'm a new french user of Jess, so I don't speak english very, sorry
> for the inconvenience.
> I would like to fire rules with Java objects based facts.
> 
> Please let's considere the following object :
> *     class A {
> *             int num;
> *             A (int newNum) { setNum (newNum); }
> *             int getNum () { return num; }
> *             void setNum (int newNum) { num = newNum; }
> *     }
> To put instances of it into facts, I made :
> *     jess.Rete rete = jess.Rete();
> *     A a1 = new Achat(1);
> *     rete.executeCommand("(defclass a A)");
> *     rete.store("A1", a1);
> *     rete.executeCommand("(bind ?a (fetch A1))");
> *     rete.executeCommand("(definstance a ?a static)");
> So I have the following fact:
> *     (a (class <External-Address:java.lang.Class>) (num 1) (OBJECT
> <External-Address:A>))
> 
> Now I would like to create a rule which, for all "a" facts, do an action.
> This is done by (for example) :
> *     rete.executeCommand("(defrule write-a " +
> *     "(a (num ?n)) => " +
> *     "(printout t ?n crlf))");
> Into the action, I can use "num" thanks to "?n".
> 
> BUT I do not know how to use the objet itself ! I would like to do something
> "like" :
> *     rete.executeCommand("(defrule write-a " +
> *     "(?object = a) => " +
> *     "(call ?object setNum 2))");
> 
> Do you know how to do ???
> 
> Thanks a lot
> 
> Jerome Poirier
> [EMAIL PROTECTED]
> 
> ---------------------------------------------------------------------
> 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]
---------------------------------------------------------------------

Reply via email to