Hi,

The answer depends on what you want to do with it when you get
it. Current releases of Jess  haven't provided the ready-made tools
to do anything with entire facts once you have a reference to one, so
none of the possibilities are trivial; I expect that one of these days
I'll put in something like the CLIPS "fact-functions" patch from the
early 6.0 days to add things like get-fact-slot, set-fact-slot, etc.

But anyway. You can, for example, pass the fact-index (in ?p) to a
userfunction, and the userfunction can then use the Java API to
manipulate the fact. For example,  here's a userfunction that given
the index of a fact and the name of a slot, retrieves the slot's
contents in Jess 5.0aX:

public class FactSlotValue implements Userfunction 
{    
  public String getName() { return "fact-slot-value"; }
  public Value call(ValueVector vv, Context context) throws ReteException
  {
    Fact f = new Fact(context.getEngine().findFactByID(vv.get(1).factIDValue()),
                      context.getEngine());
    return f.findValue(vv.get(2).stringValue());
  }
}

Given this function, you can then write deffunctions like

(deffunction print-bar (?id)
        "Print the contents of the bar slot in a fact."
        (printout t (fact-slot-value ?id bar) crlf))

You could write other UserFunctions to allow you to do other things
with Facts. As I said, expect a future version of Jess to ship with
functions like fact-slot-value.

Unfortunately, the Fact class has changed in the past, and will,
change in the future, so any functions you write of this nature might
need frequent rewriting.

I think H�kan Lindgren wrote:
> 
> Is there any way to send a fact from the fact list to a userfunction. I
> would like to do something like this:
> 
> (deftemplate XXX (slot A)(slot B))
> 
> (defrule YYY
>   ?p<-(XXX (A 2)(B 2))
>   =>
>   (userfunction ?p))
> 
> the assert and run commands are done from a java class. I have succeeded
> to send a string but I would like to send the fact.
> 
> Thanks in advance for any response. / Hakan



---------------------------------------------------------
Ernest Friedman-Hill  
Distributed Systems Research        Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
Org. 8920, MS 9214                  [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. List problems? Notify [EMAIL PROTECTED]
---------------------------------------------------------------------

Reply via email to